tim_m
i'm so nice
- Joined
- Feb 10, 2003
- Messages
- 5,539
being that i don't use terribly complicated mysql relations, i don't often need to use joins (though i'm sure there are some places i use 'WHERE a.id = b.id' when i could use joins). well here's my newest join statement
basically the sections table is a small list of the sections of the site. images is a table (for an image management system i'm developing) which associates various images that are used in the different sections. in the admin section, this query is used to get each section's name, section id, and number of images 'attached' to that section.
i know i don't really have a question or anything but meh. maybe discuss joins or something
actually i do have a question. i can't do count(b.*), it gives me an error but count(b.iid) works. does it matter, i thought i read that count(*) was optimized but can't use just '*' since it's over 2 tables, maybe it's only optimized for within one table, which kinda makes sense.
Code:
SELECT a.sid,a.name,count(b.iid) AS number
FROM sections AS a
LEFT JOIN images AS b
ON a.sid=b.sid
GROUP BY a.name;
i know i don't really have a question or anything but meh. maybe discuss joins or something
actually i do have a question. i can't do count(b.*), it gives me an error but count(b.iid) works. does it matter, i thought i read that count(*) was optimized but can't use just '*' since it's over 2 tables, maybe it's only optimized for within one table, which kinda makes sense.