Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: select query

  1. #1
    New Coder
    Join Date
    Jul 2006
    Thanked 0 Times in 0 Posts

    select query

    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?????

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    St. Catharines, Ontario Canada
    Thanked 148 Times in 139 Posts
    You could use:

    select group_concat(carid), year
    from yourtable
    group by year
    and it will give you a single row for each year with a comma delimited list of the carids from that 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.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts