Skip to content
Advertisement

create column for unread notifications in union query

I’m trying to distinguish two unioned selects. I have two tables: notification and read_notification.

notification table:

read_notification table:

I’ve managed with getting unread and read notifications like so:

and got result where unread notifications come first then read:

Now I need to distinguish them, so I need a read column where unread notifications will be marked with 1. Should look like this:

Can’t get the idea of how to form it.

Advertisement

Answer

Add it as a literal in the SELECT list.

You can also do this without UNION by using LEFT JOIN.

or with a correlated subquery

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