Share
, ,

MySQL: DISTINCT and LIMIT

  • If there is duplicate result in data but you are asked to show distinct result then command-
    SELECT DISTINCT state FROM customers
     
  •  If you are asked to find a list of 10 customers from selected tables and columns then command-
    SELECT id, name FROM customers LIMIT 10
  • Use LIMIT to select the id and name columns from customers showing 10 results, starting from the fifth-
    SELECT id, name FROM customers LIMIT 5,10




Notice:
  1. If there is duplicate data in a column then to find out unique/distinct data/result you have to use DISTINCT statement otherwise it will give you duplicate value of same query. 
  2. Here customer is table and state, id, names are columns.
  3. Use the LIMIT statement to limit the query.
  4. If you are asked to limit data for a specific range then write the range starting number first and then putting the comma(,) write the range end number.This command will show the data for that limit only. 

                                                   

0 comments:

Post a Comment