Sabtu, 15 Desember 2012

SELECT in DATABASE

Here I will explain how to make a SELECT in the database.


        1.  SELECT e.last_name, e.departement_id,
           d.departement_name
           FROM tbemployee e, tbdepartement d
          WHERE e.departement_id = d.departement_id;  












2. SELECT DISTINCT job_id, location_id
FROM tbemployee, tbdepartement
WHERE tbemployee.departement_id =
tbdepartement.departement_id
AND tbemployee.departement_id = 80;











3. SELECT e.last_name, d.departement_name,
d.location_id, l.city
FROM tbemployee e, tbdepartement d, tblocation l
WHERE e.departement_id = d.departement_id
AND d.location_id = l.location_id
AND e.commision IS NOT NULL;



4   







     4. SELECT last_name, departement_name
FROM tbemployee, tbdepartement
WHERE tbemployee.departement_id =
tbdepartement.departement_id
AND last_name LIKE '%a%';













5. SELECT e.last_name, e.job_id,
e.departement_id, d.departement_name
FROM tbemployee e JOIN tbdepartement d
ON (e.departement_id = d.departement_id)
JOIN tblocation l
ON (d.location_id = l.location_id)
WHERE LOWER(l.city) = 'toronto';











6. SELECT employee_id, first_name,last_name,salary*12
FROM tbemployee
WHERE departement_id = 60 or departement_id = 90;












7. SELECT e.employee_id, e.first_name, e.last_name, e.salary*12
FROM tbemployee e, tbdepartement d
WHERE e.departement_id = d.departement_id
AND LOWER(d.departement_name) = 'it';

8. SELECT d.departement_id, (
SELECT AVG(salary*12)
FROM tbemployee e
WHERE e.departement_id = d.departement_id)
FROM tbdepartement d;

                                                              
9. SELECT e.employee_id, e.last_name,e.salary,
d.departement_name, l.city, l.country_id
FROM tbemployee e JOIN tbdepartement d
ON (e.departement_id = d.departement_id)
JOIN tblocation l
ON (d.location_id = l.location_id)
WHERE LOWER(l.city) = 'toronto';












10.  CREATE TABLE tbemployee2 AS (
SELECT e.employee_id, e.first_name, e.last_name,e.email,e.phone_number,e.hire_date,e.job_id, e.salary, e.commision, e.manager_id, e.departement_id, e.address
FROM tbemployee e, tbdepartement d
WHERE e.departement_id = d.departement_id
AND LOWER( d.departement_name ) = 'it');








I Already example of how to use SELECT in database.
And the results are listed along with the script.




Tidak ada komentar:

Posting Komentar