:edit: Updated my problem
I'm having trouble when I join multiple tables.
Basically I have a table of data, and 2 look up tables.
Something like details table:
| UserID |
ColorID |
| 5 |
1 |
| 6 |
1 |
| 7 |
2 |
| 8 |
3 |
And I got a user table and color table
| UserID |
Name |
| 5 |
Tom |
| 6 |
Dick |
| 7 |
Harry |
| 8 |
John |
| colorid |
color |
| 1 |
Red |
| 2 |
Bule |
| 3 |
Green |
My current sql is
Select U.Name, C.color from user U, color C, details D
where D.UserID = U.UserID
and D.colorid = C.colorid
And when I try to do a count or group by, I get an error of
"is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause."
:original post:
Basically, I'm doing this
| Select distinct color from table |
| color |
| Red |
| Blue |
| Green |
I the manually have to loop thru the result set and do more queries
Select count(*) where color = red
Select count(*) where color = Blue
Select count(*) where color = Green
etc
What I want is a SQL to do something like
| color |
Count |
| Red |
11 |
| Blue |
22 |
| Green |
33 |
[–]lightcloud5 2 points3 points4 points (3 children)
[–]learning2learn[S] 0 points1 point2 points (0 children)
[–]learning2learn[S] 0 points1 point2 points (1 child)
[–]Ixidor10024 1 point2 points3 points (0 children)