You are here: Left join messes up order by « PHP SQL « IT news, forums, messages
Left join messes up order by

Posted by M@ on 06/09/05 16:30

Hi,

I have a problem with a left join. When I run it, the ordering isn't right.
Here's the SQL:

SELECT
manufacturers.man_name,
models.mdl_name,
cars.car_reg_number,
car_images.carimg_file,
MIN(car_images.carimg_order_num) AS img_order_num
FROM
manufacturers,
models,
cars
LEFT JOIN car_images
ON cars.car_id = car_images.carimg_car_id
WHERE
manufacturers.man_id = models.mdl_man_id
AND models.mdl_id = cars.car_mdl_id
GROUP BY
car_images.carimg_car_id
ORDER BY
car_images.carimg_order_num,
cars.car_price DESC


What should happen is that the images are sorted by the order number column
in car_images and the lowest value is chosen. However, what actually
happens is that the images are grouped together by the carimg_car_id field
in the car_images table but MySQL selects the most recently added image to
the database (the one with the highest ID number.)

What's wrong with my SQL statement?


Thanks in advance.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация