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
0 answers

Putting Order By, Limit and Offset in subqueries in Union All

I have got the following table that holds approx. 700K records: CREATE TABLE `trades` ( `tradeId` int(11) NOT NULL AUTO_INCREMENT, `userId` int(11) NOT NULL, `visible` int(11) NOT NULL DEFAULT '1', `sourceItem` int(11) NOT NULL, …
skiwi
  • 66,971
  • 31
  • 131
  • 216
0
votes
2 answers

MySQL: Can you specify a random limit?

Is there a way to randomize a limit number in SQL (MySQL)? What I'd like to be able to do is get a random number of results in a query to use in an insertion subquery without any server-side scripting. The query I'd love to be able to run as a…
0
votes
2 answers

SQL query (LEFT JOIN + conditions) doesn't show correct results on first entry

I have a problem with my SQL query. I am trying to query the database to get data from 3 different tables, where on one table conditions are applied. On the second entry it shows the results correctly, though on the first it lacks to show the…
yp28
  • 147
  • 11
0
votes
1 answer

CakePHP 2.1 Custom Pagination

I am using cakephp 2.1 and defined 3 tables as follows. `industries(id, name);` `movies(id, name, industry_id),` `trailers(id, name, movie_id);` I want to paginate the trailers for particular industry. So the code I have written is…
Sanganabasu
  • 943
  • 7
  • 21
  • 39
0
votes
1 answer

Using LIMIT clause in Sybase

in MySQL I am able to use LIMIT clause but not in the sybase. I have found a lot of question and answers on the net but I can't find what I want. I have tried this SELECT TOP 5 * FROM Employees ORDER BY Surname; but sybase throws and error.it…
Bizarre
  • 106
  • 2
  • 12
0
votes
1 answer

Store words in SQLite database

I am making an SQLite database in Android in which i have to store 40k words in it. I am getting the words from q txt file. I am storing the words first in a list and then from list to database. But when I store words in table and retrieve from that…
muditagarwal88
  • 548
  • 5
  • 13
-1
votes
2 answers

How can I fetch products with the highest price in SQL with LIMIT

I tried to fetch 50 products from a database with the highest price but if i set the LIMIT at 50 it's just fetching the first 50 products order by the price. This is not what i want. How can i setup the mysql query right or should i fetch all and…
user20083529
-1
votes
1 answer

How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)

I want to retrieve the Top 10 Products - weekly Rank This week product Previous week rank Last month rank 2 month ago rank 3 month ago rank 1 Watch 2 3 1 …
Ramiz Tariq
  • 387
  • 10
  • 27
-1
votes
1 answer

Row number over partition by usage

I would like to filter the below table based on the week column, but only when the year week combination is a max. In the below example I want my output to only select rows with year 2022 and week 1 as that is the latest year week combination. I am…
jackie21
  • 327
  • 1
  • 11
-1
votes
2 answers

Can't update only 1 row. How to change 1 row?

I found out that Oracle does not support LIMIT clause unlike to MySQL and to update only 1 row in table i've tried this: UPDATE "Schedule" SET "Position" = 'Manager' WHERE "Position" IN (SELECT "Position" FROM "Schedule" …
bmfdds
  • 1
  • 5
-1
votes
2 answers

Get at least last 2 rows from each row in a joined mysql 5.X tables

I got two tables: Processes idProcess data 1 XXXX 2 XXXX ... ... Tracings: idTrace idProcess 1 1 2 1 3 1 4 2 5 2 6 2 7 2 ... ... Need the last two idTrace from each idProcess ordered descending by…
-1
votes
2 answers

How to select the row with the lowest value- oracle

I have a table where I save authors and songs, with other columns. The same song can appear multiple times, and it obviously always comes from the same author. I would like to select the author that has the least songs, including the repeated ones,…
Elena
  • 17
  • 3
-1
votes
1 answer

Oracle:Get Most recent Transaction based on updated Date ad like column

Hi I am trying to get most recent transaction based on updated timestamp along with another column like i i tried with below queries but did not work. Create Table Transactions(Transaction_Id number,User_ID varchar(20),Transaction_Name…
NightHawk
  • 85
  • 1
  • 7
-1
votes
2 answers

Select atribute with max value

How can i select Company name with max count of Employers between 2 dates with using subquery, main problem is that i have 2 same dates with 2 max values, and i need to take only first of it in subquery select Company.CompanyName from Company where…
-1
votes
2 answers

Select records from a specific key onwards

I have a table that has more than three trillion records The main key of this table is guid As below GUID Value mid id 0B821574-8E85-4FB7-8047-553393E385CB 4 51 15 …