Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: select query
07-26-2006, 06:50 PM #1
- Join Date
- Jul 2006
- Thanked 0 Times in 0 Posts
below is code which I am using in a query:
SELECT DISTINCT [tblCar].[CarID], [tblCar].[Year] FROM tblCar ORDER BY [Year];
I am trying to have the query so that if two cars are entered into the tblCar and have the same year of manufacture, the year wont be displayed more than once.
Could someone tell me if this is possible and if it, is am I doing it the rite way?? If I am not doing it the rite way then, how?????
07-26-2006, 07:54 PM #2
- Join Date
- Mar 2006
- St. Catharines, Ontario Canada
- Thanked 148 Times in 139 Posts
You could use:
and it will give you a single row for each year with a comma delimited list of the carids from that year.Code:select group_concat(carid), year from yourtable group by year
alternately, if you are using php to display your information, take a look at the categories/subcategories link in my signature. you should be able to figure out how to use it to show the year once and then a list of the cars below that and then print out the year again when the model year changes.