Linker IT Software
menubar-top-links menubar-top-rechts
Home Help Search Login
Welcome, Guest. Please Login.
SQL*XL: Database to Excel bridge litLIB: Excel power functions pack ExcelLock: Locking and securing your valuable Excel spreadsheets encOffice: Protect your Excel file easy and safe encOffice: Protect your Excel file easy and safe
Pages: 1
SQL query (Read 2160 times)
Gerrit-Jan Linker
YaBB Administrator

Posts: 75
SQL query
05.12.08 at 21:08:09
SQL query
An SQL query is a type of SQL (Standard Query Language) to retrieve information from a database. Often there is much data stored in a database organised in several tables. The process to extract data from these tables is called querying, extracting, exporting. The SQL command that is used to query is the select statement. To proceed we need to get familiar with the SQL select statement.
SQL select statement
SQL commands are just simpel text commands that are sent to the database. E.g. when sending the command: select * from mytable the database will return all rows and all columns from the database table called mytable. This looks easy enough, doesn't it? Type another table name and you get the data from another table. Easy.
The where clause
Usually you don't want to download the whole table. You may for example only be interested in rows that have particular characteristics. For example in an exmployee table you may want to find all employees that earn more than 1000. This is where the where clause comes in.
The where clause is an addition to the select command we have seen so far. You simply type some conditions so the database returns only those rows that adhere to the conditions given. E.g.: select * from employees where sal > 1000
You can combine multiple conditions together. E.g.:
select * from employees
where sal > 1000
and not job = 'DIRECTOR'
and name like 'A%'
This would select rows of employeed that earn more than 1000, that are not a director and whose name start with an A.
Column list
You can be specific what data is returned by specifying the column list or to enter some formulas to process the data. For example if I am only interested to see the job title and the name I can write: select job, name from employees. Now only these two columns are returned.
Formulas can be used to do some processing or calculations on the data. Suppose there is a salary and a bonus column and you don't want to return them as separate columns but as a sum. You can write: select sal + bonus from employees.
Table joins
Sometimes the data to be retrieved is not in one table only but is stored in several tables. You can combine the data from multiple tables using joining statements in the where clause. Consider the situation that an employee works in a department. On the employee table the department id is stored and the departement name is stored in the departments table. You can retrieve all employee and department details running a query like this:
select * from employees, departments where employees.department_id =
Back to top

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Pages: 1