TorK
TorK

Reputation: 617

SQL select individual data from two tables

I have two tables User and booking

User

 Id    userphone
 1        11111111
 2        22222222
 3        33333333

Booking

 ID      bookingphone
  1       22222222
  2       11111111
  3       44444444

I want to get every individual phonenumbers from both tables Like this:

 1111111
 2222222
 3333333
 4444444

How do I do this without getting duplicates? Only individual phonenumers as in my example

Upvotes: 0

Views: 35

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521194

Use a UNION:

SELECT userphone FROM User
UNION
SELECT bookingphone FROM booking;

A UNION will, by default, remove duplicate phone numbers, which seems to be what you want to do. If you want to retain all records from both sides, then replace UNION with UNION ALL.

Upvotes: 2

Sankar
Sankar

Reputation: 7107

Try this

UNION

SELECT
  userphone
FROM user
UNION
SELECT
  bookingphone
FROM booking

Upvotes: 2

Related Questions