Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL First() Function

Tags:

sql

mysql

I am using phpMyAdmin to write some SQL code that I thought was simple but proving to be a headache. I'm using this tutorial to help me out. My goal is to get the first and last columns id's from a result set. When I do this query I get 5 rows starting at 15 and going through 11.

SELECT id
FROM boardPost
WHERE recipientId = 1
ORDER BY id DESC
LIMIT 0,5

However, when I try this query I get an error #1064: "You have an error in your SQL syntax."

SELECT FIRST(id)
FROM boardPost
WHERE recipientId = 1
ORDER BY id DESC
LIMIT 0,5
like image 366
gmustudent Avatar asked Oct 26 '25 01:10

gmustudent


1 Answers

Something like this maybe?

SELECT min(id), max(id)
from (
  select id
  from boardPost
  where recipientId = 1
  order by id desc
  limit 0,5
) t