Skip to content
Advertisement

How chceck is id is used in other column in same table

I’m using MariaDB 10.3 and I have table like:

post_shared = 0 means this is original post and is not shared.

I am looking for a way to know if the post has been shared by a particular user (coming from post_user_id). Example output is as follows:

I tried a LEFT JOIN to the same table and checked using if condition, but the code is returning me erroneous value.

Thx all for help 🙂

Advertisement

Answer

You can add a boolean flag using a correlated subquery or left join. If there are no duplicates:

As a correlated subquery, this looks like:

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