Skip to content

Linux Fun

Artikel seputar linux, teknik informatika dan sistem informasi

Menu
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Sitemap
Menu

MULTIPLE TABLE QUERIES

Posted on March 13, 2013 by linuxfun

A JOIN operation is performed when more than one table is specified in the FROM clause.  You would join two tables if you need information from both. You must specify the JOIN condition explicitly in SQL.  This includes naming the columns in common and the comparison operator.

  • 1 Example 1
  • 2 Example 2

Example 1

Find the name and courses that each faculty member teaches.
SELECT FACULTY.FACNAME, COURSENUM FROM FACULTY, CLASS WHERE FACULTY.FACID = CLASS.FACID;

FACULTY.FACNAME COURSENUM
Adams ART103A
Tanaka CIS201A
Byrne MTH101B
Smith HST205A
Byrne MTH103C
Tanaka CIS203A

When both tables have an attribute name in common, you must specify which version of the attribute that you are referring to by preceding the attribute name with the table name and a period.  (e.g., table‑name.col‑name).  This is called “qualification”.

It is sometimes more convenient to use an “alias” (an alternative name) for each table.  SQL specifies alias names in the FROM clause immediately following the actual table.  Once defined, you can use the alias anywhere in the SELECT where you would normally use the table name.

Example 2

Find the course number and the major of all students taught by the faculty member with ID number ‘F110’. (3 table JOIN)
SELECT ENROLL.COURSENUM, LNAME, MAJOR FROM CLASS , ENROLL, STUDENT WHERE FACID = ‘F110’ AND CLASS.COURSENUM = ENROLL.COURSENUM AND ENROLL.STUID = STUDENT.STUID;

ENROLL.COURSENUM

LNAME

MAJOR

MTH101B

Rivera

CIS

MTH103C

Burns

ART

MTH103C

Chin

Math

Using aliases, this would be:
SELECT E.COURSENUM, LNAME, MAJOR FROM CLASS C, ENROLL E, STUDENT S WHERE FACID = ‘F110’ AND C.COURSENUM = E.COURSENUM AND E.STUID = S.STUID;

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Sifat-Sifat Benda, Pengenalan Sifat Fisik dan Sifat Kimia
  • Konsep dan Pengertian Teori Keseimbangan Umum
  • Database Oracle
  • Perpajakan, Fungsi, Tujuan, dan Sistem Perpajakan di Indonesia
  • Teori Konsumen, Memahami Perilaku Konsumen dalam Memilih Barang dan Jasa
  • Asimetri Informasi, Perilaku Agen, Moral Hazard, Adverse Selection dan Pasar Asuransi
  • Memahami Konsep Penting dalam Ekonomi Perusahaan dan Industri, Pengambilan Keputusan, Teori Pasar, Investasi, dan Strategi Perusahaan
  • Mempelajari Konsep Keseimbangan Umum, Interaksi Pasar Barang dan Faktor Produksi serta Peran Pemerintah dalam Perekonomian
  • Efisiensi Pasar dan Peran Pemerintah dalam Meningkatkan Kesejahteraan Masyarakat, Memahami Konsep-konsep dalam Ekonomi Kesejahteraan
  • Eksternalitas dan Public Goods, Mempelajari eksternalitas, manfaat publik, biaya dan manfaat sosial, dan peran pemerintah dalam mengatasi pasar yang tidak sempurna
  • Analisis Pasar Monopoli, Memahami Monopoli, Persaingan Monopolistik, Oligopoli, Kartel, dan Pengaruhnya Terhadap Harga dan Kualitas Produk atau Jasa

Categories

  • Adobe
  • Alga
  • Algoritma
  • Algoritma Genetika
  • Android
  • Basis Data
  • Biologi SMA Kelas 10
  • Biometrik
  • Borland Delphi
  • Buku Pelajaran SMA
  • Buku Pelajaran SMK
  • Buku Pelajaran SMP
  • Business Intelligence
  • C++
  • Cacing
  • Citra Digital
  • Clustering
  • Customer Relationship Management
  • Data Flow Diagram
  • Data Mining
  • Data Warehouse
  • Database Terdistribusi
  • Databases
  • Desain Grafis
  • Ekonomi
  • Ekonomi Makro
  • Ekonomi Micro
  • Ekonomi SMA Kelas 12
  • Enterprise Resource Planning
  • Entity Relationship Diagram
  • Financial Management
  • Fuzzy
  • Game
  • Ganggang
  • Globalisasi
  • Hewan
  • Hidden Markov Model
  • Ilmu Pengetahuan Sosial SMP Kelas 9
  • Internet
  • Invertebrata
  • Jamur
  • Java
  • Keanekaragaman Hayati
  • Kebijakan Publik
  • Kecerdasan Buatan
  • Klasifikasi Makhluk Hidup
  • Knowledge Management
  • Komputer
  • Koperasi
  • Kriptografi
  • Logika Informatika
  • Manajemen
  • Manajemen Badan Usaha
  • Manajemen Proyek Sistem Informasi
  • Microsoft Acces
  • Monera
  • Multimedia
  • My SQL
  • Negara Berkembang
  • Negara Maju
  • Network Management
  • Otonomi Daerah
  • Pascal
  • Pelajaran IPA SMP Kelas 1
  • Pembelaan Negara
  • Pendidikan Kewarganegaraan SMP Kelas 9
  • Pengenalan Pola
  • Penutupan Siklus Akuntansi
  • Perang Dunia II
  • Perpajakan
  • PHP
  • PLC
  • Prestasi Diri
  • Protista
  • Prototype
  • Rekayasa Perangkat Lunak
  • Siklus Akuntansi Perusahaan Dagang
  • Sistem Informasi
  • Sistem Informasi Geografis
  • Sistem Kelistrikan
  • Sistem Pakar
  • Sistem Pendukung Keputusan
  • Sistem Pengapian
  • SMS Gateway
  • SQL Server
  • Teknik Sepeda Motor SMK Kelas 11
  • Teori Ekonomi
  • Thyristor
  • Tingkatan Manajemen
  • Tumbuhan
  • UML
  • Uncategorized
  • Vertebrata
  • Video
  • Virus
  • Visual Basic
© 2023 Linux Fun