I have tables like this
mainTable
Id | name | country
1 | John | 5
2 | Bill | 7
categoriesTable
other_table_id | category
1 | 6
1 | 12
My question is how can I say
SELECT id FROM mainTable
WHERE country=5
AND WHERE categoriesTable order_table_id=[**THE ID I JUST GOT FROM THE FIRST TABLE**] && category=6 || category=12
Then returns the number of records that match so in this case 1
Thanks!
Doesn't anyone learn how to write JOINs when they learn SQL?
SELECT m.id
FROM mainTable AS m
JOIN categoriesTable AS c ON c.other_table_id = m.id
WHERE c.category IN (6, 12)
AND m.country = 5