LEFT JOIN problems
| From: | Chris Lee | Date: | Wed, 15 Nov 2000 08:33:03 +0000 |
| Subject: | LEFT JOIN problems | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-25557@lists.php.net to get a copy of this message | ||
If I have three tables, purely for demonstration
t1 ID name
123 truck
t2 ID img
123 1.jpg
123 2.jpg
123 3.jpg
t3 ID cat
123 auto
SELECT * FROM t1, t2, t3;
ID name ID img ID cat
123 truck 123 1.jpg 123 auto
123 truck 123 2.jpg 123 auto
123 truck 123 3.jpg 123 auto
123 truck 123 4.jpg 123 auto
now this is all fine, but as you know if any of the tables are empty
then we have a problem, no results will be returned.
SELECT * FROM t1, t2 left join t3 using (ID);
I can use a left join, this will fix the case where there are no images.
but what if the product has no image or categories?
SELECT * FROM t1 left join t2 using (ID) left join t3 using (ID);
This will work now. under a few cases.
-All tables have info
-t1 has data, t2 has data, and t3 doesn't
but... mysql doesnt work like I want it to and places NULL in t3's
variables if t2 has no data. it doesnt matter whats in t3, if t2 has
nothing in it, then Im hooped.
Chris Lee