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
-1
votes
1 answer

Order mysql query with php

I want to order my posts from mysql. Newest at first. Whit this code working fine, but oldest posts at first place $sql = "SELECT * FROM post LIMIT $offset, $no_of_records_per_page"; I tried with this codes and i got an error "…
mrmiaki
  • 21
  • 3
-1
votes
1 answer

MySQL query to match exact value or next lower value

A PHP script returns a value which must be looked up in the first column of a table in a MySQL database. If the exact value returned by the script appears in that first table column, then the query needs to extract the further information from the…
nev
  • 133
  • 3
  • 10
-1
votes
2 answers

Find MIN value in a LIMITed set

I need to find a minimum value from limited number of rows in single column. Let's say I have this results table: ----------------------------------------- | id | category | class | score | ----------------------------------------- | 1 | …
sauromates
  • 11
  • 1
  • 4
-1
votes
1 answer

MSSQL query based on column priority

![enter image description here][1] my MSSQL table has these properties - id1, id2, isVerified, isRejected, score1, score2, score3. I want to show top1 value where isveried == 1, isRejected==0. After that my first priority is score1. If score1 ties…
s6r
  • 27
  • 4
-1
votes
1 answer

mysql limit collapse, which result in data interaction

I use limit offset, num to fetch data by page. But the data between pages interact, which can be seen from the primay key course_id. select version(); +---------------------+ | version() | +---------------------+ | 10.3.13-MariaDB-log…
LF00
  • 27,015
  • 29
  • 156
  • 295
-1
votes
2 answers

Write a query to find the full name of the actor who has acted in the maximum number of movies

My code is as seen below, but I'm not getting the desired answer, which is to get the full name of the actor whose done the maximum number of movies. SELECT CONCAT(" ",actor.first_name,actor.last_name) AS Full_name FROM actor INNER JOIN film_actor…
Pratham_Amitabh
  • 61
  • 2
  • 11
-1
votes
1 answer

Select Min or Max record from a table along with the corresponding name field

Assuming a table Family with Name and Age and records Bob 55 Alice 40 Marky 12 If I run Select Name,Min(Age) from Family I get Bob,12 I'm trying to ask for the fields from the single record with the lowest age yet I'm simply getting the first…
user3649739
  • 1,829
  • 2
  • 18
  • 28
-1
votes
2 answers

SQL Server : how to return highest agregated columns

Jow can I return two highest aggregated results? For example, I have a result like this: CustomerId Total --------------------- 5 1100.00 n/a 100.00 7 100.00 6 0.00 and I need to return max 2…
Dignity Dignity
  • 151
  • 2
  • 11
-1
votes
2 answers

MIN() Function with String in SQL

I have Name in employee table. I want to extract min length name. if data base contain two name with min. length both should be pick. or second question pick one name only based on alphabetically. When I am doing this like Query: Select MIN(Name)…
-1
votes
1 answer

SQL | LIMIT Clause | limit not achieved

I have the following query to get iPhones from table1 by color and limited to 10 SELECT * FROM table1 WHERE color = 'black' LIMIT 10 The above code works perfectly, When the black iPhones in table1 less than 10 I want to complete the iPhone's…
user13485306
-1
votes
3 answers

Select MAX price of a book with JOIN (2 tables) in SQL Server?

I have 2 tables CREATE TABLE BOOKS ( numbk INT PRIMARY KEY IDENTITY, nombk NVARCHAR(60), _numrub INT FOREIGN KEY REFERENCES CLASSIFICATION(numrub) ) CREATE TABLE TARIFER ( _numbk INT FOREIGN KEY REFERENCES BOOKS(numbk), …
Saad Amrani
  • 95
  • 2
  • 11
-1
votes
1 answer

ORDER BY ASC DESC & LIMIT

I would to do something such as: SELECT Position INTO lastPosition FROM ranking ORDER BY ranking.Time DESC ranking.Position DESC LIMIT 1; but i get this error: and: and: The goal is to select last row (limit 1) of ranking ordered by descendent…
shogitai
  • 1,823
  • 1
  • 23
  • 50
-1
votes
2 answers

mysql result with order by is different from order by and limit

I have a table A with columns id, age. Two queries below return different result and I don't know why: SELECT distinct a.id id FROM A a ORDER BY a.age DESC SELECT distinct a.id id FROM A a ORDER BY a.age DESC LIMIT 10 OFFSET 0 Any ideas? I would…
julius_am
  • 1,422
  • 2
  • 23
  • 42
-1
votes
1 answer

SQL LIMIT doesn't work with define

I am writing an SQL request in PHP. the request worked fine like this: $testQuery = "SELECT `title` FROM `bibliography` Where title LIKE '%$search%'"; I need to add a limit. If I add a LIMIT with a number it works fine: $testQuery = "SELECT `title`…
-1
votes
1 answer

How to select only 10 records from the table in jsp?

I'm try to select only 10 row from a table by using limit but it gives me an error, My query is SELECT * FROM table_name ORDER BY CUSTOMER LIMIT 10 It gives an error : ORA-00933: SQL command not properly ended Can anyone guide me.
User
  • 69
  • 1
  • 13
1 2 3
20
21