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.

+3


source to share


5 answers


Maybe this will 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"

      

+2


source


Try

SELECT * 
FROM `tbl_Name`
ORDER BY `Hits_Field`
LIMIT 5,5

      



LIMIT

can actually have two parameters: offset and number of records. So if you want to delete the first 5 entries and select the next 5, use LIMIT 5,5

.

+2


source


You can compensate

SELECT * FROM tbl_Name 
ORDER BY Hits_Field LIMIT 5,5

      

+1


source


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.

+1


source


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

      

0


source







All Articles