Questions tagged [sql-limit]

SQL clause to limit number of returned rows

The LIMIT clause is used to specify a maximum of rows to be returned in a SELECT query. The various SQL dialects use different syntax elements for that purpose. LIMIT x OFFSET y, is understood by MySQL, PostgreSQL, SQLite and some others RDBMS.
Example:

SELECT * FROM tbl LIMIT 10;

The SQL:2008 standard defines:

FETCH FIRST n ROWS ONLY

SQL Server uses TOP n, Oracle its rownum feature.
There is a comprehensive list on Wikipedia.

315 questions
0
votes
2 answers

retrieve random id_post sql

I have this table: +---------+------+ | id_post | post | +---------+------+ | 24 | A | | 26 | B | | 39 | C | | 57 | D | +---------+------+ I want to retrieve the a random id_post SELECT id_post FROM posts WHERE…
max
  • 3
  • 1
0
votes
3 answers

How can I get the 10 most recent rows from a database?

I want to choose an id in a table, sort it by date and show only the 10 newest entries. I have already tried following command: SELECT * FROM weather WHERE DATUM = (SELECT MAX(DATUM) WHERE ID='0')
Melvin
  • 3
  • 2
0
votes
1 answer

oracle bulk collect limit clause execution details using the sys refcursor

I am creating a stored procedure to bulk collect the data from one table (table 1) to another table (table 2) using limit clause . For example if I am loading 80000 records with the limit clause of 1000 how many times the select statement in the…
user2899615
  • 31
  • 1
  • 1
  • 10
0
votes
1 answer

Pagination custom query fetch first N rows error

I have such a long query like this in Oracle 10g (needed for custom pagination). SELECT * FROM ( SELECT FILTERED_ORDERED_RESULTS.*, COUNT(1) OVER() TOTAL_RECORDS FROM ( SELECT BASEINFO.*, …
Nick
  • 17
  • 6
0
votes
2 answers

How to find last 500 records from a table in sql with out using union,union all or minus function in sql.?

Is there any way to find the last 500 records from a table with out using union, union all or minus function? Can we achieve this using rank, row_number or dense_rank functions in sql. Thanks Rakesh
rakesh
  • 1
0
votes
0 answers

Android SQLite: FROM and LIMIT values flipped while compiling

My app has a top level menu in a RecyclerView and clicking any item opens a new activity with a submenu in a new RecyclerView. Menu item titles are stored in 'tableL1' of an SQLite database, and submenu items in 'tableL2' in a column headed…
netineti
  • 31
  • 5
0
votes
1 answer

How to select certain number of rows from large query result set in Teradata sql

I am new to Teradata sql and I have a query that selects over one million rows. I want to write teradata sql to select the first 500,000 rows, then the next 500,000 rows and then the last 100,000 + rows in my data set. For the first set I know I…
Newb
  • 35
  • 6
0
votes
1 answer

Laravel - randomly select n number of rows containing same value in certain column after applying 'order by'

In my Laravel project, in the database table ads, I have the following structure : id | col1 | col2 col2 has values like topad, bump,urgent along with empty value. I want to take all the rows from the ads table and sort them alphabetically based…
Istiaque Ahmed
  • 6,072
  • 24
  • 75
  • 141
0
votes
1 answer

How to use SUM and MAX on the same column?

So I'm having an SQL table where I will need find out the product that has been purchased the most meaning that I need to do a SUM and a group by on all the quantity of the products: SELECT PRODUCT_ID, SUM(QUANTITY) FROM PURCHASE GROUP BY…
David Mason
  • 121
  • 1
  • 7
0
votes
1 answer

MySQL check two columns for value but with a preferred column result

I have a MariaDB SQL table, with two different ID rows. Id's have been imported from a previous DB version (old_id reference is from another table), as a transitional measure searches need to be done to find id's, with a preference for the older id…
Martin
  • 22,212
  • 11
  • 70
  • 132
0
votes
2 answers

Mysql Finding the smallest n from a column

So in MySQL you can find the smallest n using sub queries or limit or even TOP in some cases. But I wanted to know if it was possible to find the smallest N without using any of these? I was told this was possible but have no idea where to start. I…
Rni224
  • 15
  • 2
0
votes
1 answer

How to limit returned rows using max characters in sqlite query

Say I have students table with one column named name as follows: | name | -------- Jhon Natalie Kocher Jonell Dickson Irvin Kiara Audet Shawna Duvall Cobey Maryellen Kenny Lindsy Taylor How to get all rows that under 6 characters so that I get the…
Bens
  • 831
  • 4
  • 12
  • 28
0
votes
1 answer

Mysql INSTR help search only 1 row that match more text

I have a table room with a field code code BED 6 BED 6 DEM I have a text to search like '... BED 6 DEM ...' If I do SELECT * FROM room WHERE INSTR('... BED 6 DEM ...',code) >0 I get these 2 rows: code BED 6 BED 6 DEM But I would like to get…
Inês Gomes
  • 4,313
  • 1
  • 24
  • 32
0
votes
1 answer

not able to do a UNION in Oracle SQL

i want to do a union of a query but getting error. SELECT NB.NETBANKID, NB.BANKNAME, NBMAP.SORTORDER, NB.BANKCODE FROM VTSMNETBNK NB INNER JOIN CGCMN.VTMESTRNETBNKMAP NBMAP ON NBMAP.NETBANKID =NB.NETBANKID WHERE NBMAP.STOREID=133 AND…
0
votes
2 answers

How we can get the data from the table by limiting the number of identical columns MySql

Yesterday I tried to retrieve data from my db table using 'user_id' as a criterion to limit the amount of data per user. I tried to get data from table https://prnt.sc/p53zhp in format like this https://prnt.sc/p541wk and limit the number of output…
Sinoto
  • 3
  • 3