Get ready for BLACK FRIDAY shopping starting in

Forums

PHP

This topic is locked

Limit returns in Second table using JOIN

Posted 29 May 2009 19:30:49
1
has voted
29 May 2009 19:30:49 Chris Trace posted:
Hey there,

This is my sql...

SELECT * ,LEFT(description ,30) As description
FROM auctionpropertyaddressdata LEFT JOIN auctionpropertyimages ON auctionpropertyaddressdata.auctionpropertyid = auctionpropertyimages.auctionpropertyid
ORDER BY propertyprice ASC

how can i limit the number of returned records in the auctionpropertyimages table to ORDER BY RAND() LIMIT 1

so i get all records from auctionpropertyaddressdata and only 1 record from auctionpropertimages table for each auctionpropertyid

Cheers

Replies

Replied 02 Jul 2009 17:05:50
02 Jul 2009 17:05:50 Roddy Dairion replied:
i don't know if this has been solved but this sounds like u need a subselect
here an e.g.
select *, (select atid from test2 b where a.acid=b.acid ORDER BY RAND() LIMIT 1
) from test1 a 


Hope this will help

Replied 26 Nov 2009 16:22:29
26 Nov 2009 16:22:29 Chris Trace replied:
thanks for that - but am a bit confused as to the final syntax of the statement

does the atid a set syntax or is a variable for the table ID field?

any help is appreciated

thanks
Replied 26 Nov 2009 16:55:33
26 Nov 2009 16:55:33 Chris Trace replied:
same issue just different code

i have this so far

SELECT *, (select [b]imagefile[/b]
FROM characterimages b
WHERE a.characterID=b.characterID LIMIT 1 ) from characters a

it is the bold underline part that i am having trouble with as this returns nothing even though the table is in the database

thanks

Reply to this topic