Click here to Skip to main content
15,892,517 members
Home / Discussions / Database
   

Database

 
GeneralRe: mySQL query question Pin
Mycroft Holmes28-Apr-10 23:35
professionalMycroft Holmes28-Apr-10 23:35 
AnswerRe: mySQL query question Pin
Chris Meech29-Apr-10 2:37
Chris Meech29-Apr-10 2:37 
QuestionHow to get the list of all dependent procedures? Pin
A M SOMAN28-Apr-10 1:48
A M SOMAN28-Apr-10 1:48 
AnswerRe: How to get the list of all dependent procedures? Pin
Henry Minute28-Apr-10 2:43
Henry Minute28-Apr-10 2:43 
AnswerRe: How to get the list of all dependent procedures? Pin
Md. Marufuzzaman28-Apr-10 22:19
professionalMd. Marufuzzaman28-Apr-10 22:19 
Questioni need a help with this problem in sql server 2005 ,, please,, please Pin
necib201028-Apr-10 0:47
necib201028-Apr-10 0:47 
AnswerRe: i need a help with this problem in sql server 2005 ,, please,, please Pin
Mycroft Holmes28-Apr-10 3:24
professionalMycroft Holmes28-Apr-10 3:24 
QuestionSelecting random top 3 listings per shop for a range of active advertising shops Pin
Graeme_Grant27-Apr-10 21:24
mvaGraeme_Grant27-Apr-10 21:24 
I’m trying to display a list of shops each with 3 random items from their shop, if they have 3 or more listings, that are actively advertising. I have 3 tables: one for the shops – “Shops”, one for the listings – “Listings” and one that tracks active advertisers – “AdShops”.

Using the below statement, the listings returned are random however I’m not getting exactly 3 listings (rows) returned per shop.

SELECT  AdShops.ID, Shops.url, Shops.image_url, 
	Shops.user_name AS shop_name, Shops.title, L.listing_id AS listing_id, 
	L.title AS listing_title, L.price as price,
        L.image_url AS listing_image_url, L.url AS listing_url

FROM	AdShops INNER JOIN
	Shops ON AdShops.user_id = Shops.user_id INNER JOIN
	Listings AS L ON Shops.user_id = L.user_id

WHERE	(Shops.is_vacation = 0 AND Shops.listing_count > 2 AND 
	 L.listing_id IN
    		(SELECT	TOP 3 L2.listing_id
	 	 FROM   Etsy_Listings AS L2
	 	 WHERE  (L2.user_id = L.user_id)
	 	 ORDER BY NEWID()
		)
	)
ORDER BY Shops.shop_name


When 'ORDER BY NEWID()' is removed, I get exactly 3 rows returned per shop but it's the first 3 listings and not random - I’m stumped. Mad | :mad: Anyone have any ideas on how to fix it? D'Oh! | :doh:

The ideal solution would be one record per store with the 3 listings (and associated data) were in columns and not rows – is this possible? Cool | :cool:
AnswerRe: Selecting random top 3 listings per shop for a range of active advertising shops Pin
Graeme_Grant27-Apr-10 22:13
mvaGraeme_Grant27-Apr-10 22:13 
GeneralRe: Selecting random top 3 listings per shop for a range of active advertising shops Pin
Mycroft Holmes28-Apr-10 3:21
professionalMycroft Holmes28-Apr-10 3:21 
QuestionHow Entertaining! [modified] Pin
Roger Wright27-Apr-10 17:35
professionalRoger Wright27-Apr-10 17:35 
AnswerRe: How Entertaining! Pin
_Damian S_27-Apr-10 17:41
professional_Damian S_27-Apr-10 17:41 
AnswerRe: How Entertaining! Pin
riced28-Apr-10 1:38
riced28-Apr-10 1:38 
GeneralRe: How Entertaining! Pin
Roger Wright28-Apr-10 9:08
professionalRoger Wright28-Apr-10 9:08 
GeneralRe: How Entertaining! Pin
riced28-Apr-10 9:33
riced28-Apr-10 9:33 
AnswerRe: How Entertaining! Pin
PIEBALDconsult28-Apr-10 3:52
mvePIEBALDconsult28-Apr-10 3:52 
GeneralRe: How Entertaining! Pin
Roger Wright28-Apr-10 9:10
professionalRoger Wright28-Apr-10 9:10 
GeneralRe: How Entertaining! Pin
PIEBALDconsult28-Apr-10 9:58
mvePIEBALDconsult28-Apr-10 9:58 
GeneralRe: How Entertaining! Pin
Roger Wright29-Apr-10 17:57
professionalRoger Wright29-Apr-10 17:57 
GeneralRe: How Entertaining! Pin
Richard MacCutchan28-Apr-10 9:35
mveRichard MacCutchan28-Apr-10 9:35 
GeneralRe: How Entertaining! Pin
PIEBALDconsult28-Apr-10 9:56
mvePIEBALDconsult28-Apr-10 9:56 
AnswerIt's all in the connection string Pin
The Man from U.N.C.L.E.28-Apr-10 21:47
The Man from U.N.C.L.E.28-Apr-10 21:47 
GeneralRe: It's all in the connection string Pin
Roger Wright30-Apr-10 7:01
professionalRoger Wright30-Apr-10 7:01 
General"It's all in the connection string" - or maybe not! Pin
The Man from U.N.C.L.E.4-May-10 22:30
The Man from U.N.C.L.E.4-May-10 22:30 
GeneralRe: "It's all in the connection string" - or maybe not! Pin
Roger Wright5-May-10 5:45
professionalRoger Wright5-May-10 5:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.