I’m trying to test a sql database that I created. To do so, I’ve got 2 tables: items and brands. Items store different fields including the name of a brand, and brands store other fields including a name. I would like to check that for each brand in items, there is a corresponding name in brands table. How would I do that ? I thought of something along the lines of:
"for each row in items"
if (count(select * from items join brands on items.brand = brands.name) == 0, select items.name, '');
But then I don’t know how to include the for statement in it… Any ideas?
You could try this:
With this query you get all records from items table, join them with corresponing brands records (if they exists) and finally take the ones not having brands corresponding record.