17
Views
2
Comments
Solved
SQL repeat result set.
Question

I wrote this sql-statement to get a shuffle list of all cards from the database. 

SELECT {Card}.[Shortname], {Card}.[Value] FROM {Card} ORDER BY NEWID(). This works, but I want a shuffled list pof all cards two times.

I expected that this was the solution:

SELECT {Card}.[Shortname], {Card}.[Value] FROM

(SELECT {Card}.[Shortname], {Card}.[Value] FROM {Card}

UNION ALL

SELECT {Card}.[Shortname], {Card}.[Value] FROM {Card})

ORDER BY NEWID()

but this doesn't work. Does anyone have any idea how to solve this problem?

2018-10-29 08-31-03
João Marques
 
MVP
Solution

Hi,


The only reason it doesn't work is because in a subquery you need to give it an alias:


SELECT cards.[Shortname], cards.[Value] FROM

(SELECT {Card}.[Shortname], {Card}.[Value] FROM {Card}

UNION ALL

SELECT {Card}.[Shortname], {Card}.[Value] FROM {Card}) cards

ORDER BY NEWID()


You can rename cards to a name of your liking.


Hope it helps.

Kind regards,
João

2020-09-26 09-10-18
Danny Eeraerts

Thanks Joao. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.