Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構

6.8. UNION

union 分頁問題

(SELECT a FROM tbl_name_a WHERE a=10 AND B=1)
UNION
(SELECT a FROM tbl_name_b WHERE a=11 AND B=2)
ORDER BY a LIMIT 10;
		
select * from (
	select a from tbl_name_a WHERE a=10 AND B=1
	union all
	select a from tbl_name_b WHERE a=10 AND B=1
) tbl_name
order by a limit 0,1;
		

6.8.1. UNION ALL

UNION ALL 不會合併重複的記錄

select a,b from tbl_name_a WHERE a=10 AND B=1
union all
select a,b from tbl_name_b WHERE a=10 AND B=1
			

6.8.2. 兩張表欄位不對等解決方法

			
SELECT * FROM
    (
    SELECT contract_address, decimals, name, symbol, seq, logo FROM token 
    UNION 
    SELECT contract_address, decimals, name, symbol, 100, 'https://www.netkiller.cn/images/eth.jpg' FROM user_token WHERE address = '0xB94054c174995AE2A9E7fcf6c7924635FBa8ECF7' AND contract_address NOT IN (SELECT contract_address FROM token)
    ) AS tmp
ORDER BY seq