Union Distinct rows but order them by number of occurrences in mysql
Posted
by Baversjo
on Stack Overflow
See other posts from Stack Overflow
or by Baversjo
Published on 2010-03-23T10:18:42Z
Indexed on
2010/03/23
10:23 UTC
Read the original article
Hit count: 228
Hi I have the following query:
SELECT o.id,o.name FROM object o
WHERE
(
o.description LIKE '%Black%' OR
o.name LIKE '%Black%'
)
UNION ALL
SELECT o2.id,o2.name FROM object o2
WHERE
(
o2.description LIKE '%iPhone%' OR
o2.name LIKE '%iPhone%'
)
Which procude the following:
id name
2 New Black iPhone
1 New White iPhone
2 New Black iPhone
I would like to UNION DISTINCT, but I would also like the result ordered by the number of occurrences of each identical row (primary: id).
© Stack Overflow or respective owner