Forgive me if this seems like common sense as I am still learning how to split my data between multiple tables.
Basically, I have two:
generalwith the fieldsuserID,owner,server,namecountwith the fieldsuserID,posts,topics
I wish to fetch the data from them and cannot decide how I should do it: in a UNION:
SELECT `userID`, `owner`, `server`, `name`
FROM `english`.`general`
WHERE `userID` = 54 LIMIT 1
UNION
SELECT `posts`, `topics`
FROM `english`.`count`
WHERE `userID` = 54 LIMIT 1
Or a JOIN:
SELECT `general`.`userID`, `general`.`owner`, `general`.`server`,
`general`.`name`, `count`.`posts`, `count`.`topics`
FROM `english`.`general`
JOIN `english`.`count` ON
`general`.`userID`=`count`.`userID` AND `general`.`userID`=54
LIMIT 1
Which do you think would be the more efficient way and why? Or perhaps both are too messy to begin with?
It’s not about efficiency, but about how they work.
UNIONjust unions 2 different independent queries. So you get 2 result sets one after another.JOINappends each row from one result set to each row from another result set. So in total result set you have “long” rows (in terms of amount of columns)