Results 1 to 3 of 3
  1. #1
    Join Date
    May 2009
    Posts
    10

    Unanswered: Returning first row from a join

    I have this...

    Code:
    SELECT d.id AS id, d.name AS name, i.url AS image_url 
    FROM destinations d, cities c, destination_images i 
    WHERE d.id IN (1,2,3) AND d.closest_city_id = c.id AND i.is_primary_photo = 1 
    ORDER BY FIND_IN_SET(d.ID, '1,2,3');
    Now I destination_images has many photos with is_primary_photo with 1. It returns all. I just want the first one.

    Thanks.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have a look at da manuel for the LIMIT clause
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by vapor
    destination_images has many photos with is_primary_photo with 1
    duh... excuse me, but why do many photos have is_primary_photo = 1 ???

    either you should change the data to match the column name, or change the column name from is_primary_photo to something like is_one_of_several_which_all_purport_to_be_primary_ photo

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •