select min(code) as AC
from Tab1e1
where id=1
Union
select min(code) as AC
from Table2
where id=1
我越來越像行下面顯示空值
ac
--
101
null
,但我不想空行。我該怎麼辦?有人能幫助我嗎?
select min(code) as AC
from Tab1e1
where id=1
Union
select min(code) as AC
from Table2
where id=1
我越來越像行下面顯示空值
ac
--
101
null
,但我不想空行。我該怎麼辦?有人能幫助我嗎?
嘗試添加此條件的每個地方
and code is not null
像
select min(code) as AC from Tab1e1 where id=1 and code is not null
Union
select min(code) as AC from Table2 where id=1 and code is not null
因爲代碼值爲null
SELECT MIN(agency)AS agencyCode FROM Table1 wps \t WHERE EXISTS(SELECT 1 FROM Table3 wup WHERE wup.sym = wps.sym AND wup.pol = wps.pol AND wup.user_id = 1) UNION SELECT MIN(機構)AS agencyCode 從表2 WPS WHERE EXISTS(SELECT 1 FROM表3 WUP WHERE wup.sym = wps.sym AND wup.pol = wps.pol 和wup.user_id = 1) – sruthi
這是我的實際查詢..請經過並幫助我 – sruthi
'select x.agencyCode from( SELECT MIN(agency)AS agencyCode FROM Table1 wps WHERE EXISTS(SELECT 1 FROM表3 WUP WHERE wup.sym = wps.sym AND wup.pol = wps.pol AND wup.user_id = 1) UNION SELECT MIN(機構)AS agencyCode FROM表2 WPS WHERE EXISTS(SELECT 1 FROM表3 WUP WHERE wup.sym = wps.sym AND wup.pol = wps.pol 和wup.user_id = 1) )x其中x.agency不是null;' –
這可以來了解,因爲沒有行相匹配的條件。如果沒有GROUP BY並且select中只有聚合函數,SQL將始終返回單行。 –