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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

mySQL query

  • 22-09-2006 6:27pm
    #1
    Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭


    I have a table which contains advertisments.

    Each Advertisment has a model number and a date entered + other info.
    I want to find the most recent 20 ads placed where the model numbers are unique.

    Anyone know of a SQL query which will do the trick? (mysql)


Comments

  • Closed Accounts Posts: 72 ✭✭TheFredJ


    SELECT DISTINCT model_number FROM table ORDER BY DateAdded desc LIMIT 20


  • Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭Peter B


    That is what I thought, until I put it in practice.

    I think the "distinct" deletes duplicate entries of model_number. And with only unique values orders by DateAdded.

    Not sure exactly how "Distinct" works but I believe it makes a result table by going down through model_number values and entering all the entries into the result table which have a model number not previously entered. It ignores a row which has a model_number that has already been entered. Then it sorts it by the DateAdded.

    It does not sort the most recent DateAdded with a particular model_number. It just sorts the order Distinct finds the unique model_number 's.

    I hope this is clear


  • Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭Peter B


    Ah, think I have found it.

    SELECT model_number, max(UNIX_TIMESTAMP(DateAdded)) as date1 FROM `ads` group by model_number order by date1 desc


Advertisement