I need a SQL solution for the following:
Lets say I have one table named "TRIPS"
[ id ][ Name ][ Duration]
[ 1 ][ Trip1 ][ 12 ]
[ 2 ][ Trip2 ][ 16 ]
[ 3 ][ Trip3 ][ 5 ]
And another table with countries each TRIP visits: LOCATIONS
[ tripId ][ country ]
[ 1 ][ US ] <--
[ 1 ][ PA ] <--
[ 1 ][ RU ]
[ 2 ][ US ] <--
[ 2 ][ PA ] <--
[ 3 ][ PA ]
[ 3 ][ RU ]
Now I want all the TRIPS which visitis "US" and "PA". So the result will be 1 and 2 becouse they both visit US and PA.
I thought I could use INNER JOIN but that only takes one row in the LOCATIONS table (afaik)
Can someone help me?
[EDIT]
I have it working with this ugly way:
SELECT * ,group_concat(distinct(LOCATIONS.country) separator ',') as COUNTRYCODES
FROM TRIPS left join LOCATIONS on TRIPS.id = LOCATIONS.tripid
group by TRIPS.id
having COUNTRYCODES like '%PA%' and COUNTRYCODES like '%US%';
But I think using "like" is an ugly solution