If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Returning first row from a join

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-29-09, 09:45
vapor vapor is offline
Registered User
 
Join Date: May 2009
Posts: 10
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.
Reply With Quote
  #2 (permalink)  
Old 05-29-09, 09:49
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,260
have a look at da manuel for the LIMIT clause
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 05-29-09, 13:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On