My query in fiddle is as follows.
select * from notification where status = 0 and ( notif_id in (select notif_id from notif_user where user_id = 1) OR notif_id in (select notif_id from notif_group where group_id = 1))
https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=cad284e77218eb37461e60b6308bf85f
The query works as expected. But, will there be any performance issues with the query. Is it possible to convert inner query to join?
Your subquery is not a dependent subquery, but independent. That is, they do not reference columns in your
notification
table, only columns in their own table.So there is no performance issue here.
You can express subqueries as union queries and compare execution plan statistics. Looking at the output in fiddle, union seems to perform slightly better.
Another way to express it is to use exists