Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Access query

Options
  • 20-02-2004 1:30pm
    #1
    Closed Accounts Posts: 1,152 ✭✭✭


    hey all! im having a problem with an access query, i have to crete a query which lists the top ten rental vehicles in a frim.

    i have tried querying using a count and sorting this in decending order but this is outputting reoccuring values. i suppose my main question is how do i stop a car number form being displayed more than once!

    thanks


Comments

  • Registered Users Posts: 19,396 ✭✭✭✭Karoma


    using DISTINCT


  • Registered Users Posts: 437 ✭✭Spunj


    No clue what your tables look like but

    try something like this:
    :
    Select  RegNo, Sum(RentalCount)  as TotalRentals
    From [YourTable]
    Group by RegNo
    Order by Sum(RentalCount) desc
    

    Replace RegNo with whatever the Vehicle Table key is.


  • Moderators, Politics Moderators Posts: 39,255 Mod ✭✭✭✭Seth Brundle


    fields:
    Table 1:- id, car
    Table2:- B_id, id, car

    SELECT TOP 10 Table1.car, Count(Table2.id) AS Table2_id, Table2.date
    FROM Table1 INNER JOIN Table2 ON Table1.id = Table2.id
    GROUP BY Table1.car, Table2.date
    ORDER BY Count(Table2.id) DESC;

    The TOP 10 part is the code you are looking for to get the latest 10.


Advertisement