I'm not a SQL guy, and I've just tried every JOIN
MySQL offers.
- I primarily need data from view1 using
WHERE
,ORDER BY
,LIMIT
with offset (the data is incorrect without those conditions.) - view1 is not limited by view2
- Data also needs to be pulled from view2, but view2 has its' own
WHERE
(or whatever's best) condition - view2 may not have corresponding data, but it shouldn't be grabbed without being linked to view1 (
NULL
s are just fine!)
I'll just give you the two SELECT
s that work for me rather than the hashes I've come up with.
For view1:
SELECT * FROM view1
WHERE column1 IS NULL OR column1 = 1
ORDER BY dateColumn DESC LIMIT index1, count1;
(index1 and count1 are IN
s i use for a stored proc)
For view2:
SELECT * FROM table2
WHERE column1 = ? AND table1_id IN (
SELECT id FROM view1
WHERE column1 IS NULL OR column1 = 1
ORDER BY dateColumn DESC LIMIT index1, count1
)
GROUP BY table1_id
(? is any arbitrary value i put in)
I'm at wits end. I have no idea how to fuse these two.
Specifics
Please note that the IN
for view2
is almost identical to the view1
query. Thanks!