Total Pageviews

2018/05/13

[PostgreSQL] How to get the first record in SELECT statement

Problem
I will get multiple record from this select statement:
1
2
3
4
5
6
7
  select * 
  from sentence 
  where intent_id in (
      select id 
      from intent 
      where project_id=5
  )

I only want the first record, how to do it?

How-To
Add LIMIT 1 at the end of the select statement:
1
2
3
4
5
6
7
8
  select * 
  from sentence 
  where intent_id in (
      select id 
      from intent 
      where project_id=5
  )
  limit 1



No comments: