មេរៀនទី២០: SQL Join

មេរៀនទី២០: SQL Join

SQL JOIN ដែលប្រើ JOIN keyword ក្នុង SQL statement ក្នុង query data ពីតារាងពីរ។

Column មួយពីតារាង join។

Join Syntax

Inner Join

SELECT * FROM table_name1

INNER JOIN table_name2

ON table_name1.column_name = table_name2.column_name

Left Join:

SELECT * FROM table_name1

LEFT JOIN table_name2

ON table_name1.column_name = table_name2.column_name

Right Join:

SELECT * FROM table_name1

RIGHT JOIN table_name2

ON table_name1.column_name = table_name2.column_name

Full Join:

SELECT * FROM table_name1

FULL JOIN table_name2

ON table_name1.column_name = table_name2.column_name

ឧទាហរណ៍ Inner Join Statement

SELECT * FROM Individual

INNER JOIN Publisher

ON Individual.IndividualId = Publisher.IndividualId

ចាំថា ប្រើតារាង table aliases ជំនួស full table name និងរក្សារ statement ដោយខ្លី។

SELECT * FROM Individual AS Ind

INNER JOIN Publisher AS Pub

ON Ind.IndividualId = Pub.IndividualId