Mysql selects everything except the first and last line
I want the database to display all rows except the first and last as I have CSS code for them.
I've tried this:
SELECT * FROM db
WHERE
keywords LIKE '%example%' LIMIT 9999 OFFSET 1
AND
keywords LIKE '%example%' DESC LIMIT 9999 OFFSET 1
Since the number of lines can increase, I cannot write the exact number.
+3
source to share
5 answers
There is really no reason to complicate your query by trying to disable these values ββat the SQL level, you can do:
$results = $db->query( /* regular query with all results */ );
array_pop($results);
array_shift($results);
// Now use $results, which now contains only the "middle" content
If you really want it at the DB level, you can use:
SELECT * FROM db
WHERE keywords LIKE '%example%'
AND id <> (SELECT MAX(ID) FROM TABLE)
AND id <> (SELECT MIN(ID) FROM TABLE)
+4
source to share
You can do this without using LIMIT
ANDOFFSET
SELECT * FROM table_name WHERE id != (SELECT MAX(id) FROM table_name) AND id != (SELECT MIN(id) FROM table_name)
SELECT * FROM db
WHERE
keywords LIKE '%example%'
AND
id != (SELECT MAX(id) FROM db)
AND
id != (SELECT MIN(id) FROM db)
here id will be your auto-increment
0
source to share