commonly used sql commands
lets know initially what is sql and how to use it
SQL is a standard computer language for accessing and manipulating databases
if we see carefully while using sql we use joins orderbys etc very commonly
The ORDER BY clause is used to sort the rows
some sample quer SELECT Company, OrderNumber FROM Orders ORDER BY Company
AND and OR join two or more conditions in a WHERE clause.
SELECT * FROM Persons WHERE FirstName='Latha' AND LastName='Chandu'
Use OR to display each person with the first name equal to "Latha", or the last name equal to "Chandu":
SELECT * FROM Persons WHERE firstname='Latha' OR lastname='Chandu'
The IN operator may be used if you know the exact value you want to return for at least one of the columns.
SELECT * FROM Persons WHERE LastName IN ('chandu','latha')
The BETWEEN ... AND operator selects a range of data between two values.
To display the persons alphabetically between (and including) "chandu" and exclusive "latha", use the following SQL:
SELECT * FROM Persons WHERE LastName BETWEEN 'chandu' AND 'latha'
With SQL, aliases can be used for column names and table names.
Sometimes we have to select data from two or more tables to make our result complete. We have to perform a join.
The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type.
SELECT E_Name FROM Employees_visualsoft UNION SELECT E_Name FROM Employees_Megasoft
so friends try to use some queries like above while dealing with typical database queries.
|
| Author: vyj 10 Jul 2007 | Member Level: Bronze Points : 0 |
Thank u.
|