pixelboy — 2012-01-16T11:07:44-05:00 — #1
I have probably an easy question which keeps my mind bugging for some days now...
I'm trying to put the following SELECT statements into 1 multi SELECT statement, PHP/MYSQL.
SELECT * FROM myTable1
SELECT * FROM myTable2
SELECT * FROM myTable3 ORDER BY RAND() LIMIT 1
SELECT row1, row2 FROM myTable4 ORDER BY id DESC LIMIT 4
I tried UNION or UNION ALL but that doesn't work because all MYSQL tables are different in row quantity.
r937 — 2012-01-16T11:11:34-05:00 — #2
use four separate queries
guido2004 — 2012-01-16T11:11:54-05:00 — #3
Then I guess it's not possible.
Edit: like he says ^^
pixelboy — 2012-01-16T12:26:03-05:00 — #4
Sometimes the mind wants it too complicated while the answer is obvious.
Thanks for keeping my life simple!
cups — 2012-01-16T12:36:28-05:00 — #5
As previous replies ... unless tables 1 and 2 share a common value in one or more fields which allows you to JOIN them.
r937 — 2012-01-16T13:22:30-05:00 — #6
or have similar columns which allows you to UNION them
michael_morris1 — 2012-01-16T22:12:46-05:00 — #7
Which brings us to another reason why "SELECT *" can be bad. It tells us nothing about your db structure OP, so there's not much in the way of suggestions we can make. Also, from each table, if you are building a combo box, you are only going to need 2 values anyway, so why pull all?
r937 — 2012-01-17T00:49:00-05:00 — #8
where did the 2-value combo box idea come from?
michael_morris1 — 2012-01-17T01:24:07-05:00 — #9
Reading too fast thinking he's talking about <SELECT> tags.