Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Memilih di beberapa tabel dengan UNION

Terima kasih telah memperbarui kueri; sekarang kita dapat melihat bahwa kondisi WHERE hanya diterapkan pada terakhir Permintaan UNION. Anda harus salah satu tambahkan klausa WHERE itu ke setiap kueri, atau bungkus sebagai subpilihan dan terapkan klausa WHERE ke dalamnya.

select s.id as id, s.email as email, s.password as password, s.role as role from tblStudents s
where email = "[email protected]"
union
select a.id as id, a.email as email, a.password as password, a.role as role from tblAdmin a
where email = "[email protected]"
union
select t.id as id, t.email as email, t.password as password, t.role as role from tblTeachers t
where email = "[email protected]"

atau

SELECT * FROM (
select s.id as id, s.email as email, s.password as password, s.role as role from tblStudents s
union
select a.id as id, a.email as email, a.password as password, a.role as role from tblAdmin a
union
select t.id as id, t.email as email, t.password as password, t.role as role from tblTeachers t
) foo where email = "[email protected]"


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. SQLSTATE[HY000] [1045] Akses ditolak untuk 'username'@'localhost' pengguna menggunakan CakePHP

  2. MySQL:PILIH dari server lain

  3. Menggunakan Penasihat Pencadangan Basis Data untuk Mengotomatiskan Tugas Pemeliharaan

  4. Php mysql untuk melakukan tugas setelah 30 detik

  5. Bagaimana saya bisa mencegah Hibernate + c3p0 + MySql membuat koneksi tidur dalam jumlah besar?