I am working on a featured page that lists records in different categories. 5 Newest, 5 Least Viewed, 5 Most Viewed..
That part is not difficult:
Newest: SELECT TOP 5 * ORDER BY ID_Record DESC
Least: SELECT * FROM tbl_Name WHERE ORDER BY Hits_Field LIMIT 5
Most: SELECT * FROM tbl_Name WHERE ORDER BY Hits_Field DESC LIMIT 5
Here is my question.. Because the newest records are possibly the least viewed they could feasibly show up in both queries. I want to eliminate the 5 newest records from consideration. How do I write a SQL Statement like this:
SELECT * FROM tbl_Name
WHERE (NOT THE 5 NEWEST ID_Record BUT ALL OTHERS STILL IN CONSIDERATION)
ORDER BY Hits_Field LIMIT 5
I know there is a NOT IN consideration, but I am new to this and need help writing a nested statement for this.
May be this could work:
"SELECT * from table_name where Id_Record not in (SELECT Id_Record from table_name order by Hits_Field LIMIT 5) order by Hits_Field LIMIT` 5"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With