I am making a MySQL query where I want to retrieve an ID but only if I find a match for it in all the rows which I specify in the query.
Table: view_layout_rows
ID owner rows
___________________
49 1 2
50 1 2
Table: view_layout_rows_columns
ID row columns
___________________
49 1 5
49 2 4
50 1 5
50 2 5
SELECT vlr.id
FROM view_layout_rows vlr
INNER JOIN view_layout_rows_columns vlrc
ON vlr.id = vlrc.id
WHERE vlr.rows = 2
AND (vlr.owner = 0 OR vlr.owner = 1)
AND all of the following conditions should be satisfied:
(vlrc.row = 1 AND vlrc.columns = 5)
(vlrc.row = 2 AND vlrc.columns = 5)
Only ID 50 should be returned. 49 should NOT be returned as it only satisfies the first of the final two clauses.
How might I go about this? (Please note, I asked this question previously but my requirement was unclear. Second attempt.) Thanks in advance for any suggestions.