![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi folks, I have a db which is similar to the example Name | Country | Type test | USA | Nm test2 | UK | Nb test3 | USA | Nc test4 | USA | Nm What I want to know is if there is a simple SQL statement to do the following: 1) Select all entries where country = USA (for example) 2) Group by Type 3) Display each group under each heading Type - i.e. Nm test | USA test4 | USA Nc test3 | USA I'm going to keep looking, but I want to keep my SQL to a minimum and wondered what the official way of doing this would be. Thanks A |
#3
| |||
| |||
|
|
UKuser wrote: Hi folks, I have a db which is similar to the example Name | Country | Type test | USA | Nm test2 | UK | Nb test3 | USA | Nc test4 | USA | Nm What I want to know is if there is a simple SQL statement to do the following: 1) Select all entries where country = USA (for example) 2) Group by Type 3) Display each group under each heading Type - i.e. Nm test | USA test4 | USA Nc test3 | USA I'm going to keep looking, but I want to keep my SQL to a minimum and wondered what the official way of doing this would be. Thanks A Item 3 is the tricky one, although it would be easy with a bit of php (or similar, presumably) provided that's available to you. Anyway, here's the query: SELECT type,name,country FROM table WHERE country = 'USA' GROUP BY type ORDER BY type |
#4
| |||
| |||
|
|
Hi, Thanks for the SQL. It was point 3 which I wanted to see if it could be done in the same SQL statement or if it was separate. |
#5
| |||
| |||
|
|
What I want to know is if there is a simple SQL statement to do the following: 1) Select all entries where country = USA (for example) 2) Group by Type 3) Display each group under each heading Type - i.e. |
#6
| |||
| |||
|
|
Anyway, here's the query: SELECT type,name,country FROM table WHERE country = 'USA' GROUP BY type ORDER BY type |
#7
| |||
| |||
|
|
strawberry wrote: Anyway, here's the query: SELECT type,name,country FROM table WHERE country = 'USA' GROUP BY type ORDER BY type I get all muddle-headed with this whole GROUP BY thing. What does the record of a GROUP BY query look like? Does it have a special column, or go beyond just two-dimensional tables? |
#8
| |||
| |||
|
|
I've never tried to execute generated SQL in a MySQL stored procedure, so I'm not even sure it has a function to do so. |
![]() |
| Thread Tools | |
| Display Modes | |
| |