..<< = More Info = >>..

Wednesday, August 20, 2008

MySql The ORDER BY

The ORDER BY keyword is used to sort the result.

Sort the Rows
The ORDER BY clause is used to sort the rows.

Example
To display the company names in alphabetical order:
SELECT Company, OrderNumber FROM Orders
ORDER BY Company

Example
To display the company names in alphabetical order AND the OrderNumber in numerical order:
SELECT Company, OrderNumber FROM Orders
ORDER BY Company, OrderNumber

Example
To display the company names in reverse alphabetical order:

SELECT Company, OrderNumber FROM Orders
ORDER BY Company DESC

Example
To display the company names in reverse alphabetical order AND the OrderNumber in numerical order:

SELECT Company, OrderNumber FROM Orders
ORDER BY Company DESC, OrderNumber ASC

Source : w3schools.com

MySQL Basic Statement

The SQL SELECT Statement

  • The SELECT statement is used to select data from a table. The tabular result is stored in a result table (called the result-set).
  • SELECT column_name(s)
    FROM table_name
  • SELECT LastName,FirstName FROM Persons
The WHERE clause is used to specify a selection criterion.
  • The WHERE Clause
    To conditionally select data from a table, a WHERE clause can be added to the SELECT statement.
  • Syntax
    SELECT column FROM table
    WHERE column operator value
  • SELECT * FROM Persons
    WHERE City='Sandnes'
The INSERT INTO Statement
  • The INSERT INTO statement is used to insert new rows into a table.
  • Syntax
    INSERT INTO table_name
    VALUES (value1, value2,....)
  • INSERT INTO table_name (column1, column2,...)
    VALUES (value1, value2,....)
The Update Statement
  • The UPDATE statement is used to modify the data in a table.
  • Syntax
    UPDATE table_name
    SET column_name = new_value
    WHERE column_name = some_value
  • UPDATE Person SET FirstName = 'Nina'
    WHERE LastName = 'Rasmussen'
The DELETE Statement
  • The DELETE statement is used to delete rows in a table.
  • Syntax
    DELETE FROM table_name
    WHERE column_name = some_value
  • DELETE FROM Person WHERE LastName = 'Rasmussen'
  • Delete All Rows
    It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:
  • DELETE FROM table_nameorDELETE * FROM table_name

Source : w3schools.com

Custom Search
 

Bursa 2000 | Find Better Jobs