Share
, , ,

MySQL: Sorting Results

  • 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




Notice:
  1. When you will write your column name like this "customers.address"where address is you column and customer is your table, this is call fully qualified name. You should use fully qualified name to sort out data when there is more than one table with the same named column.
  2. If you want to sort out your result in a specific order then use ORDER BY statement.
  3. Here name, state, address are columns and customers is table.

                                               

0 comments:

Post a Comment