1

i have a query that looks as following:

(SELECT title FROM pjeducations LIMIT 5)
UNION
(SELECT title FROM pjeducations WHERE animal != "all" LIMIT 5)
UNION
(SELECT title FROM pjeducations ORDER BY price DESC LIMIT 5)

Some of the results in the second select are the same as in the first, same with the third select.

The problem is that the duplicate results automaticly get removed but i would like them to stay in it. Anyone know how to achieve this?

Tony
  • 9,672
  • 3
  • 47
  • 75
vincent
  • 205
  • 1
  • 4
  • 10

2 Answers2

8

Use UNION ALL instead.

D'Arcy Rittich
  • 167,292
  • 40
  • 290
  • 283
  • Works perfect, reaction was so fast that i have to wait 13 minutes to accept your answer, tyvm for the fast reply – vincent Nov 26 '10 at 22:20
3
Union All 

preserved duplicate results

Ali Tarhini
  • 5,278
  • 6
  • 41
  • 66
  • Personal choice, but when I post an answer and find it's a duplicate that doesn't add anything beyond the earlier one, I remove it. – T.J. Crowder Nov 26 '10 at 22:25
  • i do the same, but sometimes an answer gets posted while i am writing my answer so i dont get to know if they are duplicates – Ali Tarhini Nov 26 '10 at 22:28
  • 1
    @Microgen: Sure you do, they're right there when you save your answer. Happens to me all the time, I do my answer, click save, and find that someone else said exactly the same thing, so I click delete. (Off-topic: If you reply to someone's comment, put "@username:" at the front so they get notified.) – T.J. Crowder Nov 26 '10 at 22:41
  • @T.J. Crowder: and if someone gave the same answer as you, but sooner, I think it is worth upvoting theirs after you delete yours. It's almost like voting for yourself :) – D'Arcy Rittich Nov 27 '10 at 15:14