Share
Showing posts with label SQL-Tutorial-1. Show all posts
Showing posts with label SQL-Tutorial-1. Show all posts
  • If you want to run multiple queries at a time then command for selecting city and id from customers-
    SELECT city FROM customers;
    SELECT id FROM customers;
  • You run the any query by giving line breaks and white spaces, it wont affect the command/result-
    SHOW COLUMNS
    FROM customers

  • 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


  • If you have more tables in your database those who are holding columns of same name then you can sort out the specified column and its data form a table by this command-
    SELECT customers.address FROM customers
  • If you want sort your result in alphabetic order or numeric order then command-
    SELECT name FROM customers ORDER BY name
    SELECT name, address FROM customers ORDER BY id
  • If you want to sort multiple columns then the command should be like this-
    SELECT name, state, address FROM customers ORDER BY state, name


  • Retrieve more than one column of a table in the same SELECT statement-
    SELECT name,zip FROM customers
  • Show all the columns of a table in the same SELECT statement-
    SELECT * FROM customers


  • To see your databases command-
    SHOW DATABASES
  • To see your tables in a database command-
    SHOW TABLES
  • To see all the column names in a table named customer command-
    SHOW COLUMNS FROM customers
  • If you want to select a column named city from the table customer then command-
    SELECT city FROM customers