I have a table like this:
tableA: id, a, b, c
sample data:
1, x, y, sample1-get-by-y
2, x, y, sample2-get-by-y
3, x, '', sample1-get-by-x
4, x, '', sample2-get-by-x
5, '', '', saple1-general
6, '', '', saple2-general
I want to get the data like this:
if I have data where field b is 'y' - get me those rows (row 1 and 2)
if I don't have rows where field b is 'y', look for rows where field a is 'x' - (rows 3 and 4)
if I don't have rows where field a is 'x', then get me the rows where fields a and b are empty (rows 5 and 6)
(if I'd run this on the data from above I should only get rows 1 and 2, because once i do get result for b=y I should stop looking for other options)
so basicly those are the 3 queries-
SELECT * FROM tableA
WHERE b= 'y';
SELECT * FROM tableA
WHERE a= 'x';
SELECT * FROM tableA
WHERE a = '' AND b = ''
what I need help with, is how do I combine all of this into 1 query? so that I won't have to run a query and then check the result and run the next one if needed and etc..
thanks in advance!