小编典典

如何使用where命令一次使用union?

sql

我想在PHP中使用的查询与where命令where notifikasi = '1'2 tables,但 我只看到1台
即得到where notifikasi = '1'我怎么可以让我的两个表 得到where notifikasi = '1'

SELECT a.id_skd as idab,a.nl as nl1, a.aa as aa1,a.jp as jp1, a.syarat_lampiran as syarat_lampiran1,a.riwayat_kelola as riwayat_kelola1,a.notifikasi as notifikasi1 
FROM skd a
UNION ALL 
SELECT b.id_skb as idab, b.nl as nl1, b.aa as aa1, b.jp as jp1, b.syarat_lampiran as syarat_lampiran1,b.riwayat_kelola as riwayat_kelola1, b.notifikasi as notifikasi1 
FROM skb b  
WHERE notifikasi='1' 
ORDER BY riwayat_kelola1 DESC 
LIMIT 1

阅读 184

收藏
2021-04-14

共1个答案

小编典典

您必须重复该WHERE子句,它仅适用于一个SELECT查询,而不适用于整个查询UNION

SELECT a.id_skd as idab,a.nl as nl1, a.aa as aa1,a.jp as jp1, a.syarat_lampiran as syarat_lampiran1,a.riwayat_kelola as riwayat_kelola1,a.notifikasi as notifikasi1 
FROM skd a
WHERE notifikasi = '1'
UNION ALL 
SELECT b.id_skb as idab, b.nl as nl1, b.aa as aa1, b.jp as jp1, b.syarat_lampiran as syarat_lampiran1,b.riwayat_kelola as riwayat_kelola1, b.notifikasi as notifikasi1 
FROM skb b  
WHERE notifikasi='1' 
ORDER BY riwayat_kelola1 DESC 
LIMIT 1
2021-04-14