Skip to content
Advertisement

How to get one extra record for LEFT JOIN to represent a record not include on the left joined table

I have a database with two tables one table (shops) has an admin user column and the other a user with less privileges. I plan to LEFT JOIN the table of the user with less privileges. When I retrieve the data, the records for the admin user must be on a separate row and must have NULL values for the left joined table followed by records of users with less privileges (records of the left joined table) if any. I am using MySQL.

I have looked into the UNION commands but I don’t think it can help. Please see the results bellow of what I need.

Thank you.

Here is an example structure of the databases and some sample data:

Diagram of database

Advertisement

Answer

I think you need union all:

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