MySQL Forums
Forum List  »  Newbie

Re: Simple SQL query.... maybe
Posted by: Chris Stubben
Date: March 24, 2005 03:12PM

Hi,

Mysql also has a nice (non-standard SQL) feature that allows hidden fields in the GROUP BY statement..

http://dev.mysql.com/doc/mysql/en/group-by-hidden-fields.html


If this query returns zero results (ie, every col1-col2-col3 combination is unique)

select col1, col2, col3, count(*) from table group by 1,2,3 having count(*)>1;

...then the group by with hidden fields should work. Note, I'm only grouping by the first two columns below

select col1, col2, max(col3), col4, col5, col6, col7, col8, col9, col10 from table group by 1,2;


Otherwise you're stuck with a subquery or join and will get some multiple rows for each col1-col2-max(col3) records.


Chris

Options: ReplyQuote


Subject
Written By
Posted
March 24, 2005 05:01AM
Re: Simple SQL query.... maybe
March 24, 2005 03:12PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.