I have tables with listings, categories and one that maps them to each other. So a listing can then be placed in multiple categories. Something like the following:
listings table
id
title
etc
categories table
id
category_name
etc
map table
listing_id
category_id
When I need to get all of the information for listings within a single category (in this case the category with the id of 18), The following works fine:
SELECT *
FROM (`listings`, `map`)
WHERE `map`.`category_id` = 18
AND map.listing_id = listings.id
My problem is how can I do a similar type of query, but now I need to find those distinct listings that are within two categories. For example, what if I need to return only those distinct listings that are in both category_id = 18 AND category_id = 20? Would this require some type of join?