Database & SQL

Moderators: None (Apply to moderate this forum)
Number of threads: 1174
Number of posts: 2221

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Newbie question Posted by BJ008 on 4 Nov 2004 at 11:25 AM
This message was edited by BJ008 at 2004-11-4 11:58:0

This message was edited by BJ008 at 2004-11-4 11:28:47

Hi,

I have table with four columns (A, B, C, D).
I need something like this :

SELECT COUNT(A) FROM MyTable GROUP BY A, B, DISTINCT(C), DISTINCT(D)

By this query I want to say : I want to group rows with same A, same B, unique C, unique D.
But I cann't use DISTINCT in GROUP BY clause. How can I write it using legal SQL query ???

I will really thanful you if you help me, much thanks.




Report
Re: Newbie question Posted by infidel on 4 Nov 2004 at 11:28 AM
: Hi,
:
: I have table with four columns (A, B, C, D).
: I need something like this :
:
: SELECT COUNT(A) FROM MyTable GROUP BY A, B, DISTINCT(C), DISTINCT(D)
:
: But I can use DISTINCT in GROUP BY clause. How can I write it using legal SQL query ???
:
: I will really thanful you if you help me, much thanks.

Using distinct in a group by clause doesn't even make sense. When you say "group by" something that means find all the records that have the same value in that field and aggregate them together.

I'm not exactly sure what you're trying to do. Your example doesn't make enough sense for me to guess.


infidel

$ select * from users where clue > 0
no rows returned


Report
Re: Newbie question Posted by BJ008 on 4 Nov 2004 at 11:46 AM
: : Hi,
: :
: : I have table with four columns (A, B, C, D).
: : I need something like this :
: :
: : SELECT COUNT(A) FROM MyTable GROUP BY A, B, DISTINCT(C), DISTINCT(D)
: :
: : But I can use DISTINCT in GROUP BY clause. How can I write it using legal SQL query ???
: :
: : I will really thanful you if you help me, much thanks.
:
: Using distinct in a group by clause doesn't even make sense. When you say "group by" something that means find all the records that have the same value in that field and aggregate them together.
:
: I'm not exactly sure what you're trying to do. Your example doesn't make enough sense for me to guess.
:
:
: infidel
:
:
: $ select * from users where clue > 0
: no rows returned
: 

:
:

I mean this : I want to group rows with same A, same B, unique C, unique D.
Report
Re: Newbie question Posted by infidel on 15 Nov 2004 at 7:52 AM
This message was edited by infidel at 2004-11-15 7:54:15

: : : Hi,
: : :
: : : I have table with four columns (A, B, C, D).
: : : I need something like this :
: : :
: : : SELECT COUNT(A) FROM MyTable GROUP BY A, B, DISTINCT(C), DISTINCT(D)
: : :
: : : But I can use DISTINCT in GROUP BY clause. How can I write it using legal SQL query ???
: : :
: : : I will really thanful you if you help me, much thanks.
: :
: : Using distinct in a group by clause doesn't even make sense. When you say "group by" something that means find all the records that have the same value in that field and aggregate them together.
: :
: : I'm not exactly sure what you're trying to do. Your example doesn't make enough sense for me to guess.
: :
: :
: : infidel
: :
: :
: : $ select * from users where clue > 0
: : no rows returned
: : 

: :
: :
:
: I mean this : I want to group rows with same A, same B, unique C, unique D.
:

Ok, how about:

select ...
from table
group by A, B

Unless you explicitly group by a column, it is not grouped, so there's no need to use any distinct qualifier for the other columns.

infidel

$ select * from users where clue > 0
no rows returned







 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.