-1

I have 3 tables :

Table A1 : ID|Name|Date|Id_person
Table B1 : ID|Name|Date|Id_person
Table C1 : ID|Name|Date|Id_person

I want a query like:

select * from table A1 as a , table B1 as b , table C1 as c where a.Id_person=1 or b.Id_person=1 or c.Id_person=1

I get result only if id_person=1 in the 3 tables, And i get no result if just one the 3 table don't respect the condition.

How to get result from the tables even if one of theme don't respect the condition (id_person=1).

Cœur
  • 37,241
  • 25
  • 195
  • 267
osiris23
  • 77
  • 1
  • 7

3 Answers3

1

You can try:

SELECT * FROM A1 WHERE Id_person=1 UNION SELECT * FROM A2 WHERE Id_person=1 UNION SELECT * FROM A3 WHERE Id_person=1
Felipe Arenales
  • 991
  • 1
  • 8
  • 19
0

Try that :

select * from table A1 as a 
left join table B1 as b on a.Id_Person = b.Id_Person
left join table C1 as c on a.Id_Person = c.Id_Person

See this post : LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

Community
  • 1
  • 1
Pierre-Luc Bolduc
  • 485
  • 1
  • 5
  • 18
0

You can try UNION:

SELECT * FROM A1 as a WHERE a.Id_person=1
UNION ALL
SELECT * FROM B1 as b WHERE b.Id_person=1
UNION ALL
SELECT * FROM C1 as c WHERE c.Id_person=1
Sean Zhang
  • 108
  • 6