select from table only if the id exist in that table mysql pdo php -


i want create select query using join on 3 or more tables. have 3 tables namely t1, t2, t3 , common column id existing in 3 tables. want select 3 table if id exists in table query this.

select * t1  inner join t2 on t1.id = t2.id  inner join t3 on t2.id = t3.id  t1.id = 1 , t2.id = 1 , t3.id = 1 

the query returning values if id exists in 3 tables. if not in table example t3 not return anything. looking way if not exist in t3 should proceed select t1 , t2

is need?

select *  t1  inner join t2 on t1.id = t2.id  left join  t3 on t2.id = t3.id  t1.id = 1 , t2.id = 1 , (t3.id = null or t3.id = 1) 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -