Exclude 5 newest entries from consideration
I am working on a featured page that lists posts in different categories. 5 Newest, 5 Least Viewed, 5 Most Viewed ..
This part is easy:
Newest: SELECT TOP 5 * ORDER BY ID_Record DESC
Smaller: 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's my question .. Since the newest posts are perhaps the least viewed, they might actually appear in both queries. I want to exclude the 5 newest entries from consideration. How to 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-NOT consideration, but I am new to this and need help writing a nested statement for this.
source to share
Use the Limit parameters.
1) To eliminate the newest 5 entries
SELECT * FROM tbl_Name ORDER BY Hits_Field ASC LIMIT 5 [Parameter to display from **5** th record], 1000[Parameter to display up to 1000 record];
2) To eliminate least viewed (oldest) 5 entries
SELECT * FROM tbl_Name ORDER BY Hits_Field DESC LIMIT 5 [Parameter to display from **5** th record], 1000[Parameter to display up to 1000 record];
Hope it helps.
source to share
The logic would be Take the 10 least viewed (to have enough entries to eliminate 5), remove all that also show up in the newest (up to 5, but may be less), then limit that number to 5
Try EXCEPT or MINUS, something like
SELECT * FROM
(
SELECT * FROM tbl_Name WHERE ORDER BY Hits_Field LIMIT 10
EXCEPT
SELECT TOP 5 * ORDER BY ID_Record DESC
)
LIMIT 5
source to share