SQL DE JOIN VE ÖRNEKLER

---------------------------------------
SELECT * FROM REGIONS
---------------------------------------
SELECT COUNT(*) FROM COUNTRIES

SELECT * FROM REGIONS,COUNTRIES -- TABLOLARI BİRLEŞTİREBİLİRİZ

SELECT * FROM REGIONS R ,COUNTRIES C WHERE R.REGION_ID=C.REGION_ID-- ANLAMLI CIKTI ALABİLİRİZ

SELECT * FROM DEPARTMENTS
SELECT * FROM LOCATIONS

SELECT D.DEPARTMENT_NAME, L.CITY FROM DEPARTMENTS D ,LOCATIONS L WHERE D.LOCATION_ID=L.LOCATION_ID

SELECT E.FIRST_NAME, E.LAST_NAME, J.JOB_TITLE FROM JOBS J, EMPLOYEES E  WHERE J.JOB_ID=E.JOB_ID

SELECT E.FIRST_NAME, E.LAST_NAME, J.JOB_TITLE FROM JOBS J JOIN EMPLOYEES E ON J.JOB_ID=E.JOB_ID-- JOİNLEDE AYNI İŞLEMİ YAPABİLİRİZ.

SELECT COUNT (*) FROM DEPARTMENTS -- TOPLARI TOPLAMINI SAYAR

SELECT DISTINCT DEPARTMENT_ID FROM EMPLOYEES
-----------------------------JOIN VE WHERE İLE YAPIM-------------------------------------
SELECT E.FIRST_NAME,E.LAST_NAME, D.DEPARTMENT_NAME 
FROM EMPLOYEES E, DEPARTMENTS D 
WHERE E.DEPARTMENT_ID=D.DEPARTMENT_ID
ORDER BY 2

SELECT E.FIRST_NAME,E.LAST_NAME, D.DEPARTMENT_NAME 
FROM EMPLOYEES E LEFT JOIN DEPARTMENTS D 
ON E.DEPARTMENT_ID=D.DEPARTMENT_ID
ORDER BY 2
-----------------------------JOIN VE WHERE İLE YAPIM-------------------------------------
SELECT E.LAST_NAME,E.FIRST_NAME,D.DEPARTMENT_NAME,J.JOB_TITLE 
FROM EMPLOYEES E ,DEPARTMENTS D ,JOBS J 
WHERE E.DEPARTMENT_ID=D.DEPARTMENT_ID AND E.JOB_ID=J.JOB_ID AND D.DEPARTMENT_ID=100


SELECT E.LAST_NAME,E.FIRST_NAME,D.DEPARTMENT_NAME,J.JOB_TITLE 
FROM EMPLOYEES E  JOIN DEPARTMENTS D ON E.DEPARTMENT_ID=D.DEPARTMENT_ID AND D.DEPARTMENT_ID =100
JOIN  JOBS J ON  E.JOB_ID=J.JOB_ID

------------------------------JOIN VE WHERE İLE YAPIM------------------------------------

SELECT E.LAST_NAME, L.STREET_ADDRESS FROM LOCATIONS L,EMPLOYEES E ,DEPARTMENTS d

WHERE LAST_NAME='Chen'

------------------------------JOIN VE WHERE İLE YAPIM------------------------------------

SELECT R.REGION_NAME,E.LAST_NAME,l.STREET_ADDRESS FROM EMPLOYEES E 
JOIN DEPARTMENTS D ON E.DEPARTMENT_ID=D.DEPARTMENT_ID
JOIN LOCATIONS L ON D.LOCATION_ID=L.LOCATION_ID
JOIN COUNTRIES C ON C.COUNTRY_ID=L.COUNTRY_ID
JOIN REGIONS R ON R.REGION_ID=C.REGION_ID

WHERE E.LAST_NAME LIKE '%Chen%'

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir