Link to home
Start Free TrialLog in
Avatar of GamesNET2
GamesNET2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

MySQL Select distinct query problem

Hi there,

I have the code below - when I run it it does not give me a DISTINCT list of 'title', however if i take away col_id_6 then it works,

Any ideas?


SELECT DISTINCT exp_channel_titles.title, exp_matrix_data.col_id_5
FROM exp_channel_titles
LEFT JOIN exp_channel_data ON exp_channel_titles.entry_id = exp_channel_data.entry_id 
LEFT JOIN exp_relationships ON exp_channel_data.entry_id = exp_relationships.rel_child_id
LEFT JOIN exp_relationships AS exp_rel ON exp_rel.rel_child_id = exp_relationships.rel_parent_id
LEFT JOIN exp_matrix_data ON exp_rel.rel_parent_id = exp_matrix_data.entry_id
WHERE exp_channel_data.channel_id = 1 AND exp_matrix_data.col_id_5 IS NOT NULL
ORDER BY exp_matrix_data.col_id_5 ASC
LIMIT 0, 10

Open in new window

Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

You mean 5 I guess :)

What columns are in your output if you change to: select * from ...
hi,
try adding
 group by exp_channel_titles.title

Open in new window

instead of distinct
cus i think distinct a, b you give the cross distinct cvalues
Avatar of GamesNET2

ASKER

Ineed it was 5, the GROUP BY works for the grouping, but then the ORDER BY doesn't work properly...

?!
ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi GamesNET2, how are you doing? Made some progress?
Yes! Sorry I was so caught up in the success of it I forgot to come back, will award points tomorrow from a desk!
this article might give more insight about this kind of "problems":
https://www.experts-exchange.com/A_3203.html