Luego de investigar en diversos repositorios y sitios webs al terminar encontramos la solución que te enseñamos a continuación.
Ejemplo 1: cómo unir tablas en sql
JOINING 2TablesinsqlSELECT X.Column_Name , Y.Column_Name2
FROM TABLES1_NAME X
INNERJOIN TABLES2_NAME Y ON X.Primary_key = Y.Foreign_key;--FOR EXAMPLE--GET THE FIRST_NAME AND JOB_TITLE--USE EMPLOYEES AND JOBS TABLE--THE RELATIONSHIP IS JOB_IDSELECT E.FIRST_NAME , J.JOB_TITLE
FROM EMPLOYEES E
INNERJOIN JOBS J ON J.JOB_ID = E.JOB_ID;
Ejemplo 2: unir múltiples tablas sql
SELECT TableA.*, TableB.*, TableC.*, TableD.*FROM TableA
JOIN TableB
ON TableB.aID = TableA.aID
JOIN TableC
ON TableC.cID = TableB.cID
JOIN TableD
ON TableD.dID = TableA.dID
WHEREDATE(TableC.date)=date(now())
Ejemplo 3: unir tres tablas sql
Suppose we are having three table named as
Student_details
Attendance_details
Batch_details
And we have toapplyjoin these three tablesfor fetching records
Example query:
select column_names
from Student_detail as s join Attendance_details as a on
s.s_id = a.s_id join Batch_details as b on
s.s_id = b.s_id;
Here in the above example we implemented simplejoin but you change it with own join requirements.
Ejemplo 4: sql une 3 tablas
SELECTcolumn-names
FROMtable-name1 JOINtable-name2
ONcolumn-name1 =column-name2
WHERE condition
Ejemplo 5: 3 uniones en sql
SELECT e.FIRST_NAME ,-- coming from EMPLOYEES table
d.DEPARTMENT_NAME ,-- coming from DEPARTMENTS table
l.CITY ,-- coming from LOCATIONS table
c.COUNTRY_NAME ,-- coming from COUNTRIES table
r.REGION_NAME -- coming from REGIONS tableFROM EMPLOYEES e
INNERJOIN DEPARTMENTS d on e.DEPARTMENT_ID = d.DEPARTMENT_ID
INNERJOIN LOCATIONS l on l.LOCATION_ID = d.LOCATION_ID
INNERJOIN COUNTRIES c on l.COUNTRY_ID = c.COUNTRY_ID
INNERJOIN REGIONS r on c.REGION_ID = r.REGION_ID ;
Finalizando este artículo puedes encontrar las referencias de otros usuarios, tú además tienes la opción de mostrar el tuyo si lo deseas.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)