Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / General DB Topics / General DB Topics / December 2004

Tip: Looking for answers? Try searching our database.

Mysql: group by and displaying any row with not null value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
leifwessman@hotmail.com - 28 Dec 2004 13:57 GMT
How can I modify this query to fit my needs?

SELECT EMAIL, USERNAME, COUNT(*) AS C FROM REVIEWS GROUP BY EMAIL ORDER
BY C DESC

EMAIL may not be NULL, USERNAME may be NULL.

Example of rows in table REVIEWS:

EMAIL, USERNAME, CREATED
"someone@somewhere.com", NULL, 2004-12-01
"anyone@anywhere.com", "Anyone", 2004-12-01
"someone@somewhere.com", "Someone", 2004-12-11
"someone@somewhere.com", "SOMEONE", 2004-12-13
"someone@somewhere.com", NULL, 2004-12-16

Result of the query:

"someone@somewhere.com", NULL, 3
"anyone@anywhere.com", "Anyone", 1

I would like the result to be:

"someone@somewhere.com", "SOMEONE", 3
"anyone@anywhere.com", "Anyone", 1

since the latest not null value for the user with email
someone@somewhere.com is "SOMEONE".

Is that possible?

Leif
Albert Grein?cker - 29 Dec 2004 16:50 GMT
I hope I understood your question right...
maybe isnull could solve your problem, which means...

SELECT EMAIL, USERNAME, COUNT(*) AS C FROM REVIEWS where not isnull(email)
GROUP BY EMAIL ORDER  BY C DESC

Albert

> How can I modify this query to fit my needs?
>
[quoted text clipped - 28 lines]
>
> Leif
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.