Distinct and Limit example in MySQL

Distinct and Limit example in MySQL

Hi,

How to use the distinct and limit with SQL query in MySQL?

Thanks

View Answers

July 12, 2016 at 8:01 PM

Hi,

Here is example of distinct in SQL

select distinct(last_name) from email;

select distinct(last_name) from email where email_count >100;

Here is example of limit in MySQL:

mysql> select * from email;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
| Rajeev     | Singh     | [email protected] |         500 |
| Dinesh     | Singh     | [email protected] |         200 |
+------------+-----------+----------------------+-------------+
3 rows in set (0.00 sec)

mysql> select * from email limit 0,1;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
+------------+-----------+----------------------+-------------+
1 row in set (0.00 sec)

mysql> select * from email limit 1,2;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Rajeev     | Singh     | [email protected] |         500 |
| Dinesh     | Singh     | [email protected] |         200 |
+------------+-----------+----------------------+-------------+
2 rows in set (0.00 sec)

mysql> select * from email limit 1,1;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Rajeev     | Singh     | [email protected] |         500 |
+------------+-----------+----------------------+-------------+
1 row in set (0.00 sec)

mysql> select * from email limit 2,1;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Dinesh     | Singh     | [email protected] |         200 |
+------------+-----------+----------------------+-------------+
1 row in set (0.00 sec)

mysql> select * from email limit 1,2;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Rajeev     | Singh     | [email protected] |         500 |
| Dinesh     | Singh     | [email protected] |         200 |
+------------+-----------+----------------------+-------------+
2 rows in set (0.00 sec)

mysql>

Thanks


July 12, 2016 at 8:02 PM

Hi,

You can find more explanation at Mysql Limit.

Thanks


July 18, 2016 at 7:41 AM

Check following video:

Thanks









Related Tutorials/Questions & Answers:
Distinct and Limit example in MySQL
Distinct and Limit example in MySQL  Hi, How to use the distinct and limit with SQL query in MySQL? Thanks   Hi, Here is example...) from email where email_count >100; Here is example of limit in MySQL
Hibernate Criteria Count Distinct Example
Count Distinct? Thanks   Here is an example of Hibernate Criteria...Hibernate Criteria Count Distinct Example  I am learning Hibernate and trying to find good example of Hibernate. I want example of Hibernate
Advertisements
Mysql Limit
_table` LIMIT  X,Y; Understand with Example The Mysql Limit Tutorial... Mysql Limit       Mysql Limit is used to limit your query result to those which fall
Mysql Limit
; X,Y; Understand with Example The Mysql Limit Tutorial describe you... Mysql Limit       Mysql Limit is used to limit your query result to those which fall within
Hibernate criteria Distinct_Root_Entity Example
Hibernate criteria Distinct_Root_Entity Example  How to create Criteria DistinctRootEntity Example in Hibernate? Thanks   Example program of hibernate criteria DistinctRootEntity. Check the tutorial hibernate criteria
PHP SQL Limit
PHP SQL Limit       This example illustrates how to execute LIMIT operator of mysql in PHP. ... of the table data. For example, the LIMIT 0,5 retrieves the row starting from row number
PHP SQL Limit
PHP SQL Limit This example illustrates how to execute LIMIT operator of mysql in PHP.  In this example we create a limit.php page, in which we execute a query with LIMIT operator. In the LIMIT operator we put minimum and maximum
hibernate criteria Distinct Result Example
hibernate criteria Distinct Result Example In this Example, We will discuss about hibernate criteria query, In this example we create a criteria instance... method. In This example search the result according to Criteria
SQL SELECT DISTINCT Statement
SQL SELECT DISTINCT Statement       In this example we will show you the usage of Distinct clause with the select statement. The SQL Distinct clause is used with the Select
Order by example in MySQL
Order by example in MySQL  Hi, How to use the order by in MySQL? Thanks   Hi, The order by clause in used in MySQL for ordering the result in ascending or descending order. For example following query order the data
Count distinct value in HQL.
Description: This example counts the number of employee having distinct salary by using... Count distinct value in HQL.  How do you count distinct value in HQL?   count(distinct fieldName) returns number of distinct value
php mysql fetch array example
php mysql fetch array example  How to fetch data from mysql and store it into an array in PHP? Please post an example. Thanks in Advance
hibernate criteria Distinct_Root_Entity
hibernate criteria Distinct_Root_Entity In this Tutorial, We will discuss about hibernate criteria query, In this example we create a criteria instance... method. In This example search the result according to Criteria
Example of sorting results in MySQL
Example of sorting results in MySQL  Hi, How to sort the results in MYSQL query? Thanks   Hi, You can use the order by clause in SQL statement to sort the data in ascending or descending orders. Lets consider
Mysql Last
Mysql Last       Mysql Last is used TO limit Mysql query result that fall in a specified range... of the Tutorial provides you an example from 'Mysql Last'. To elaborate
login page php mysql example
login page php mysql example  How to create a login page for user in PHP Mysql? Please provide me a complete tutorial. Thanks in Advance
example of before insert trigger in mysql
example of before insert trigger in mysql  Hi, How to create a simple before insert trigger in MySQL? Thanks   Hi, The before insert... in MySQL database server and executed on the server itself. So, its very fast. First
mysql select into table from another table example
mysql select into table from another table example  Can you suggest the correct example of select into table from another table example in MySQL... from one table into another table. Check the example at MySQLselect into new
MySQL take backup of a table - example code needed
MySQL take backup of a table - example code needed  How to take backup of a table in MySQL? I have a database which contains many tables. What is the command to take the backup of one table with data from database? Thanks
Hibernate Criteria Count Distinct
=criteria.list(); An Example of counting distinct record in an application...Hibernate Criteria Count Distinct The Hibernate Criteria count distinct is used to count the number of distinct records in a table. Following a way to use
MYSQL - mysql copy table to another table example by creating new table
MYSQL - mysql copy table to another table example by creating new table  Hi, I have a table with many fields and hue data is in it. I want to create... the query: create table <newtable> select * from <old table>; Example
SQL SELECT DISTINCT Statement
SQL SELECT DISTINCT Statement       In this example we will show you the usage of Distinct clause with the select statement. The SQL Distinct clause is used with the Select statement
Hibernate example step by step in Eclipse with MySQL
is using Eclipse IDE and the example program connects to MySQL Database. Check...Hibernate example step by step in Eclipse with MySQL  Hi, I am total... and looking for any good Hibernate example for learning step by step in Eclipse
Example of Average, Sum, Min and Max functions in MySQL
, Here is few example of aggregate functions in MySQL: mysql> select * from...Example of Average, Sum, Min and Max functions in MySQL  Hi, How to use the aggregate functions like Average, Sum, Min and Max in MySQL? Thanks
Hibernate Criteria Distinct
Hibernate Criteria Distinct The Hibernate Criteria Distinct API search and display the distinct result Consider the following SQL SELECT DISTINCT name FROM student WHERE roll_no=2; The above SQL will return the  distinct name
MySQL :Regex Example
MySQL :Regex Example In this tutorial we are going to discuss about regex with example in JDBC. MySQL : Regex You can use Regular Expressions in mysql.... {n,m}  It defines the limit of string that is string occurrence
MySQL Not in Example
MySQL Not in Example       MySQL Not in is used to set the update of  records for only... with ExampleADS_TO_REPLACE_1 The Tutorial shows you an example from MySQL
MySQL allowMultiQueries JSP Example
MySQL allowMultiQueries JSP Example In this section we will discuss about how to run multiple sql queries in Java. This example is given here.... This example explains you all the steps for allowing multiple queries using MySQL
ModuleNotFoundError: No module named 'limit'
ModuleNotFoundError: No module named 'limit'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'limit' How to remove the ModuleNotFoundError: No module named 'limit'
Mysql Last
Mysql Last       Mysql Last is used TO limit Mysql query result that fall in a specified..._TO_REPLACE_1 The Section of the Tutorial provides you an example from 'Mysql Last
Spring 3 MVC Login Form Example with Database MySql
Spring 3 MVC Login Form Example with Database MySql  Sir i have checked your project of Spring 3 MVC Login Form Example But Sir Not able to do It with database Mysql. Can you Provide code for login with database. Thanks
Servletoutputstream size limit.
Servletoutputstream size limit.  What is the maximum size of ServletOutputStream
Servletoutputstream size limit.
Servletoutputstream size limit.  What is the maximum size of ServletOutputStream?   By default size is set to 10MB.You can increase your message size maximum 2000000000 bytes. That is size limit is 2000000000
ModuleNotFoundError: No module named 'json-mapper-distinct'
ModuleNotFoundError: No module named 'json-mapper-distinct'  Hi...: No module named 'json-mapper-distinct' How to remove the ModuleNotFoundError: No module named 'json-mapper-distinct' error? Thanks   Hi
Hibernate Criteria Limit
statement will fetch 4 records  An Example of Criteria Limit is given below...Hibernate Criteria Limit There may be situation where you may want some limited no of records from databases. In hibernate you can set the limit of records
ASSIGN TIME LIMIT
(System.in); /*add some command such a time limit assign for next two commands..."); } } i.e if a user do not give any value for any time limit (say 5 sec
ModuleNotFoundError: No module named 'limit-coverage'
ModuleNotFoundError: No module named 'limit-coverage'  Hi, My... named 'limit-coverage' How to remove the ModuleNotFoundError: No module named 'limit-coverage' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'no_limit_nester'
ModuleNotFoundError: No module named 'no_limit_nester'  Hi, My... named 'no_limit_nester' How to remove the ModuleNotFoundError: No module named 'no_limit_nester' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'time_limit'
ModuleNotFoundError: No module named 'time_limit'  Hi, My Python... 'time_limit' How to remove the ModuleNotFoundError: No module named 'time_limit' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'aiohttp-limit'
ModuleNotFoundError: No module named 'aiohttp-limit'  Hi, My... 'aiohttp-limit' How to remove the ModuleNotFoundError: No module named 'aiohttp-limit' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Flask-Limit'
ModuleNotFoundError: No module named 'Flask-Limit'  Hi, My Python... 'Flask-Limit' How to remove the ModuleNotFoundError: No module named 'Flask-Limit' error? Thanks   Hi, In your python environment
JDBC Example with MySQL
JDBC Example with MySQL       Mapping MySQL Data Types in Java Data types of MySQL... for transferring data between an database using MySQL data types and a application using
hibernate criteria Distinct
Java Mysql Connection Example
Java Mysql Connection Example We are going to discus how to connect  MySQL in java. We have been provide some classes and API with which we will make... in to connect with the database. Requirements to connect with the MySQL database
MYSQL - SQL
to select first rows from tha table for example.... limit 2 is used to select...MYSQL  how to select last row in table?(MYSQL databse)   How to select last row of the table in mySql Here is the query given below
plz give me program to this: Given a string and a number ‘n’, find the ‘n’th distinct repeating character.
plz give me program to this: Given a string and a number ?n?, find the ?n?th distinct repeating character.    Given a string and a number ?n?, find the ?n?th distinct repeating character. For example, Input: Abracadabra, 1
2. Given a string and a number ‘n’, find the ‘n’th distinct repeating character.
2. Given a string and a number ?n?, find the ?n?th distinct repeating character.    Given a string and a number ?n?, find the ?n?th distinct repeating character. For example, Input: Abracadabra, 1 Abracadabra, 2 Abracadabra, 3
MySQL Attribute
MySQL Attribute This example illustrates how to use the COLLATE attribute in MySQL. In this example we use the COLLATE attribute to define the attribute of the table. In the query below character data types (CHAR, VARCHAR, TEXT) can
MySQL Average Command
MySQL Average Command This example illustrates how to execute the Average command in MySQL. In this example we create a select query to find the average of 'lastAccess' field.  ADS_TO_REPLACE_1 Query
Get the limit position and capacity of a double type buffer.
Get the limit position and capacity of a character buffer. In this tutorial you will see how to get the limit position and capacity of a character buffer. The given example illustrate the use of limit() method which returns the buffer

Ads