I have a weird thing to do and this would probably imply a weird query. Basically what I have until now is:
SELECT * FROM locations WHERE name IN ('city1','city2','country1','city3');
This works fine, but I want to alter this query. Say I want to somehow group city1 with country1, so if one of them returns a row (is a valid selector for the query), then the other one shouldn’t execute anymore. Something like:
SELECT * FROM locations WHERE name IN (('city1' OR 'country1'),'city2','city3');
This query works, but only returns the values that contain city2 and city3, so not what I want.
Would something like this be possible?
EDIT:
To be more specific, here is an example.
I have 3 locations, which (in PHP), I’m going to break into 5:
Bucharest, Romania
New York
Barcelona, Spain
these will become 3 sets of arrays:
array( 'Bucharest', 'Romania' )
array( 'New York' )
array( 'Barcelona', 'Spain' )
I want to lookup the continent of each of these locations. I will search for all of them in the same query using IN clause from MySQL. I want the query to return 3 rows: Europe,North America,Europe.
However, my query can’t find the entry for Bucharest, because it’s not in the table, so I would want to search for the next term in the array: Romania.
Hope this clears things up.
I don’t think this is the best solution, but I think you can achieve it like this:
which will select all “non-grouped” names and then select only first row from second select (it will be “city1” if it’s matched or “country1” if it’s not, or nothing)
But if you want it more general, it has to be done somehow else I think 🙂