I can not write the correct sql select query. There are 2 tables - garage_items and users_items. The first stores all existing items and their data (such as name, price, uniqueness), the second stores data about items of a particular user (user ID, user ID, quantity). It is necessary to display ALL existing items, but those that belong to the user mark the variable is_owned == 1. BUT! If the item is unique (written in garage_items, as special == 1) and it is NOT at the user - it is not necessary to output it, if it is unique and has a user or is not unique at all - output.

  • Left join and use user_id from users_items as is_owned. condition of display to write in where. - Ipatiev
  • one
    Paste the table of objects from the user to the left join without forgetting to specify the desired user directly in ON. Then in where you specify your options for the conditions, given the fact that if the record for the user was not found, then any fields in the second table will be NULL. Well, in the query selection list, set 1 to is_owned if the field in the second table is not null - Mike

0