• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

MySQL version differences

Joined
Jun 6, 2003
Messages
60
I created a select query that works in version 4.1 and does not in 4.0

It goes a little something like this...

Code:
select * from `table1`
left join (select `id` from `table2` order by `id` limit 1) on table1.id = table2.id

This works in 4.1, but 4.0 gives an error at left join ( so I can't use the nested select inside the left join. Does MySQL 4.0 not support that?
 
Yea, I've tried to rewrite it but I can't think of anything that would replicate the limiting of 1 row.

Code:
select p.product_id, i.image_id
from `products` as p
left join `product_images_links` as i on (p.product_id = i.product_id)

There are multiple products and multiple images per product and I want to return only 1 image per product. How should I do it without using 2 queries?
 
Yea, I've tried to rewrite it but I can't think of anything that would replicate the limiting of 1 row.

Code:
select p.product_id, i.image_id
from `products` as p
left join `product_images_links` as i on (p.product_id = i.product_id)

There are multiple products and multiple images per product and I want to return only 1 image per product. How should I do it without using 2 queries?

what happens if you use "where" instead of "on"?

Code:
select p.product_id, i.image_id
from `products` as p
left join `product_images_links` as i where p.product_id = i.product_id
 
You can use GROUP BY, for example
Code:
select p.product_id, i.image_id
from `products` as p
left join `product_images_links` as i on (p.product_id = i.product_id)
group by p.product_id
 
Oh, duh, group by product_id. I kept trying to group by image_id. Thanks, this gets me what I need.
 
Back
Top