I have a table with 9 rows.
$id=5
If i use SELECT * FROM tbl WHERE id>=$id
i get the 5,6,7,8,9 rows. To this query I want to add the result of SELECT * FROM tbl WHERE id<$id
so I will get the final 5,6,7,8,9,1,2,3,4 rows.
This is to avoid going two times in database then add the result set in php.
EDIT: Yes order is important. Thank you guys for the fast response. Thank you @knittl(Accepted answer) and @Swanand for the best answers.
Retrieves rows from the database and enables the selection of one or many rows or columns from one or many tables in SQL Server.
An asterisk (" * ") can be used to specify that the query should return all columns of the queried tables. SELECT is the most complex statement in SQL, with optional keywords and clauses that include: The FROM clause, which indicates the table(s) to retrieve data from.
You can obviously retrieve multiple columns for each record, and (only if you want to retrieve all the columns) you can replace the list of them with * , which means "all columns". So, in a SELECT statement, writing * is the same of listing all the columns the entity has.
you want all rows? if the order is what you are looking for, sort your result set:
SELECT * FROM tbl
ORDER BY id >= $id DESC, id ASC
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