score:1
Accepted answer
select * from table as t1
where (select count(*) from table as t2
where t1.user_id = t2.user_id and t2.id < t1.id) <3
Read More
- SQL Statement, always list 3 entries of a sort
- What is the SQL statement for requesting column entries only once per entry
- Not all parameters were used in the SQL statement when inserting list to mysql
- sql select statement to list companies depending of its members campaign status
- SQL statement to count corresponding entries while having a strict sequence (logical)
- What SQL statement have to use to get list of non duplicate id's from 1 table, but 2 columns
score:0
If you want only 3 rows, you can use limit
:
select * from myTable limit 3;
score:0
SELECT * FROM table LIMIT 3
score:1
SELECT *
FROM table
ORDER BY ...
LIMIT 3
The LIMIT clause takes two arguments: number of rows to return, and an offset if you want to display something other than the first X rows. Details here in the MySQL docs.
More questions
- How to convert JSON data with a list into an MariaDB SQL Insert statement that uses dynamic columns
- SQL statement in Java to sort by date (month)
- How to concatenate a list with conditional entries to one string with SQL
- Match comma seperated list with input in SQL statement
- sql statement order by with condition always failed?
- SQL Query to find missing entries
- What's the SQL statement for returning multiple averages from a single table dynamically
- List all available cars for a given date SQL
- Java Prepared statement Sql query error
- Loop an If Statement for each row in Sql table
- MYSQL SQL pass value from executed to a subsequent sql statement
- MySQL - Order a Group By Statement With a Column Not in List
- Insert Two List of values in play framework SQL anorm
- SQL Sort by RAND and then sort by something else
- SQL issues in JOIN statement
- Sort sql result by occurence of a set of keywords
- Looping sql statement return so slow
- How to make sure that SQL statement is executed and only then start next code step
- SQL get user.emails from user_id list
- How to sort array list in "zig-zag" in PHP?
- Resolving "Arithmetic overflow error converting varchar to data type numeric" in SQL for insert statement
- IF, ELSE statement for sql query
- Cannot sort results in sql by more than 1 column after using CASE
- Select SQL statement on related tables
More questions with similar tag
- Where is the MySQL query cache file saved?
- What should be the datatype of a sql table's column if we are inserting `NOW()` in the column
- Update a column based on two matching values of a column in two tables
- MySql Or statement functionally not making sense
- Can one connection get details of another? Or, how can I get the most detailed pending transaction report possible?
- How can I get value(10) from such array, $A= Array ( [Count(funded_by)] => 10)?
- Display different styles on alternate rows of table (within a loop)
- Date ranges in SQL
- Select multiple row without duplicate
- Sort by Referrer (quite complicated)
- MySQL Select range date between two columns
- using html5 standalone app using deskshell to connect to mysql
- MySql query doesn't work in php
- My Select query is not working in Spring MVC 3 using MySql Database
- Is there a way for mysql to allow 1 of 2 foreign keys to be null?
- GoLang How to load nested objects using GORM
- Set value or NULL if not found
- MySQL Stored Proc returning NULL values when i call the 2 OUT parameters - see code
- Why mysql odbc connector 64 bits does not work well with VBA despite my system is running fully on 64 bits?
- Setting an object returned from PDO in its own class
- mysql error 1064 when creating table. What can I check for?
- Trying to pass a student key from a html form to a php file to scan a database
- select distinct column and then related columns in php/sql
- data not gettinf inserted in mysql table
- Rails MySQL cannot single mass insert
- select all columns except one
- Using a unique reference as primary key in MySQL
- SQLAlchemy: query using tables in two MySQL schemas
- What is the best way to allow users to search for items
- How to insert double values to MySQL from C# UWP
Source:
stackoverflow.com