How to get data from three or more tables

I need to display distinct data between three tables. How to do this requirement.

FirstTable:

9999999999                     
8888888888           
7777777777
6666666666
5555555555

SecondTable:

7777777777
9999999999

ThirdTable:

8888888888

i want output in this format.

6666666666
5555555555

Answers


Use LEFT JOIN

   SELECT T1."Col"
     FROM Table1 T1
LEFT JOIN Table2 T2 
       ON T1."Col" = T2."Col"
LEFT JOIN Table3 T3 
       ON T1."Col" = T3."Col"
    WHERE T2."Col" IS NULL 
      AND T3."Col" IS NULL 

Output:

|        COL |
--------------
| 6666666666 |
| 5555555555 |
See this SQLFiddle

For the data you gave us, you can try this:

    select YourColumn from Table1
minus
    select Yourcolumn from Table2
minus
    select YourColumn from Table3

This however wouldn't give you entries that existed in Table 3 but not tables 1 ND 2. I second the suggestion that you improve the question.


Need Your Help

Tips for writing security classes for user authentication and authorisation

security language-agnostic

I have a bunch of objects in my application (Organisations, Individuals, Orders, etC) and I need a nice clean way to decide which users can and can't view/edit these objects. User have a range of

Calling a controller's action without a named route in Rails 3

ruby-on-rails ruby-on-rails-3

In Rails 3, is there a way to link to a controller's action using ajax without having a named route?