Tuhinga Tuhinga
Te whakamahi i te wetereo/tauākī pātai UNION ORDER BY mō te pātengi raraunga MySQL
MySQL Kaiwhakahaere UNION
Ma tenei akoranga e whakaatu ki a koe te wetereo me nga tauira o te kaiwhakahaere MySQL UNION.
whakaahuatanga
Ka whakamahia te kaiwhakahaere MySQL UNION ki te whakakotahi i nga hua o nga korero SELECT e rua, neke atu ranei ki te huinga hua kotahi.He maha nga korero SELECT ka tango i nga raraunga taarua.
wetereo
Hōputu wetereo kaiwhakahaere MySQL UNION:
SELECT expression1, expression2, ... expression_n FROM tables [WHERE conditions] UNION [ALL | DISTINCT] SELECT expression1, expression2, ... expression_n FROM tables [WHERE conditions];
Parapeta
- whakapuaki1, whakapuaki2, ... whakapuaki_n: Tīwae hei tiki.
- tepu: Ko te ripanga raraunga hei tiki.
- Ko nga tikanga: Kōwhiringa, paearu rapu.
- WHAKAMAHI: Ka taea, tangohia nga raraunga taarua mai i te huinga hua.Kua whakakorehia e te kaiwhakahaere UNION nga raraunga ma te taunoa, no reira karekau he paanga o te whakakē DISTINCT ki te hua.
- KATOA: Ka taea, ka whakahoki i nga huinga hua katoa, tae atu ki nga taarua.
pātengi raraunga demo
I roto i tenei akoranga, ka whakamahia e matou te tauira raraunga chenweiliang.
Anei nga raraunga mai i te ripanga "Paetukutuku":
mysql> SELECT * FROM Websites; +----+--------------+---------------------------+-------+---------+ | id | name | url | alexa | country | +----+--------------+---------------------------+-------+---------+ | 1 | Google | https://www.google.cm/ | 1 | USA | | 2 | 淘宝 | https://www.taobao.com/ | 13 | CN | | 3 | 陈沩亮博客 | http://www.chenweiliang.com/ | 4689 | CN | | 4 | 微博 | http://weibo.com/ | 20 | CN | | 5 | Facebook | https://www.facebook.com/ | 3 | USA | | 7 | stackoverflow | http://stackoverflow.com/ | 0 | IND | +----+---------------+---------------------------+-------+---------+
Anei nga raraunga mo te "taupānga" APP:
mysql> SELECT * FROM apps; +----+------------+-------------------------+---------+ | id | app_name | url | country | +----+------------+-------------------------+---------+ | 1 | QQ APP | http://im.qq.com/ | CN | | 2 | 微博 APP | http://weibo.com/ | CN | | 3 | 淘宝 APP | https://www.taobao.com/ | CN | +----+------------+-------------------------+---------+ 3 rows in set (0.00 sec)
SQL UNION tauira
Ko te tauākī SQL e whai ake nei ka tīpako i ngā whenua motuhake katoa (ko ngā uara motuhake anake) mai i ngā ripanga "Paetukutuku" me "taupānga" :
Akoranga
SELECT country FROM Websites UNION SELECT country FROM apps ORDER BY country;
SQL UNION KATOA tauira
Ka whakamahia e te tauākī SQL e whai ake nei te UNION ALL hei tīpako i ngā whenua katoa (tae atu ki ngā uara tāruarua) mai i ngā ripanga "Paetukutuku" me "taupānga" :
Akoranga
SELECT country FROM Websites UNION ALL SELECT country FROM apps ORDER BY country;
SQL UNION KATOA me WHERE
Ka whakamahia e te tauākī SQL e whai ake nei a UNION ALL hei tīpako i ngā raraunga katoa mō Haina (CN) mai i ngā ripanga "Paetukutuku" me ngā ripanga "taupānga" (tae atu ki ngā uara tāruarua):
Akoranga
SELECT country, name FROM Websites WHERE country='CN' UNION ALL SELECT country, app_name FROM apps WHERE country='CN' ORDER BY country;
Ko te tumanako, ka whai hua ki a koe te tuhinga "Union Order By Query Syntax/Statement Usage in MySQL Database" i tohaina ki te blog a Chen Weiliang ( https://www.chenweiliang.com/ ).
Tukuna mai te hononga o tēnei tuhinga: https://www.chenweiliang.com/cwl-475.html
