I have a problem when i try to change a query with LIMIT from MYSQL to SQL-Server.
Check that :
SELECT *
FROM tableEating
WHERE person = '$identity'
LIMIT 1;
I tried to change it with some queries but nothing work.
The SQL LIMIT clause restricts how many rows are returned from a query. The syntax for the LIMIT clause is: SELECT * FROM table LIMIT X;. X represents how many records you want to retrieve. For example, you can use the LIMIT clause to retrieve the top five players on a leaderboard.
In MySQL the LIMIT clause is used with the SELECT statement to restrict the number of rows in the result set. The Limit Clause accepts one or two arguments which are offset and count. The value of both the parameters can be zero or positive integers.
If you don't need to omit any rows, you can use SQL Server's TOP clause to limit the rows returned. It is placed immediately after SELECT. The TOP keyword is followed by integer indicating the number of rows to return. In our example, we ordered by price and then limited the returned rows to 3.
LIMIT does not work in T-SQL.
You have to use TOP instead, like this:
SELECT TOP(1) * FROM tableEating WHERE person='$identity';
I hope that will work for you.
As Aaron says, you also need an ORDER BY
if you don't want to get an arbitrary row.
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