I have generated an sql to query a database table where posts from users are saved.But I am getting error executing it.I have tested it here , It also tells me that it is incorrect and the problem lies in users_user_id section.I can't figure out what might be wrong here.Can any one help me with this error.
My userpost table structure is following:
post_id,post,title,users_user_id
sql:
SELECT title FROM userpost LIMIT 5 OFFSET 10 WHERE users_user_id=9
LIMIT
always come after all keywords.
Corrected SQL:
SELECT title FROM userpost WHERE users_user_id=9 LIMIT 5 OFFSET 10
Generally, SELECT query has following sequence:
SELECT
Fields List
FROM
WHERE
GROUP BY (if needed)
ORDER BY (if needed)
LIMIT (This always come at end and if limit is not specified,
query will return all records from result set.)
Try this way :
SELECT title FROM userpost WHERE users_user_id=9 LIMIT 5 OFFSET 10
where clause use after from.
Write your where condition
first then use limit
. LIMIT always come after all keywords.
SELECT title FROM userpost WHERE users_user_id=9 LIMIT 5 OFFSET 10
where
should be use before limit
SELECT title FROM userpost WHERE users_user_id=9 LIMIT 5 OFFSET 10
change:
SELECT title FROM userpost LIMIT 5 OFFSET 10 WHERE users_user_id=9
to:
SELECT title FROM userpost WHERE users_user_id=9 LIMIT 5 OFFSET 10
limit should be after where condition
SELECT title FROM userpost WHERE users_user_id=9 LIMIT 5 OFFSET 10
LIMIT always come at last position
SELECT title FROM userpost WHERE users_user_id=9 LIMIT 5,10
I hope this will work
You need to change your Query. Always where condition
place before LIMIT
and OFFSET
:
SELECT title FROM userpost WHERE users_user_id = 9 LIMIT 5 OFFSET 10;
Try this way
And LIMIT
should be after where condition
SELECT title FROM userpost WHERE users_user_id=9 LIMIT 5 OFFSET 10
You can set offset with limit as per below-
SELECT title FROM userpost WHERE users_user_id=9 LIMIT 10, 5;
Where after limit first argumet is offset and 2nd is for no. of record means limit.