Skip to content
Advertisement

How to get only specific record from multiple tables?

I have tables ‘table1‘, ‘table2’,’table3‘ and ‘table4’ . ’table1’ has a column ‘account’ on basis of I need to get record from ‘table2’ or ‘table3’ or ‘table4’ with respect of another column ‘user_id’.

I am using query like

using this I am getting lots of NULL values because each record of table1 will have only record in either ‘table2’ or ‘table3’ or ‘table4’.

Present output is like –

needed is like

t2,t3 and t4 can have more than 1 column to select.

Advertisement

Answer

It would be much simpler to use the COALESCE() function:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement