Mavzu: UNION standart so’zidan foydalanish.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mexmonxonalar |
| mysql |
| sayohat_agentligi |
| test |
+--------------------+
5 rows in set (0.06 sec)
mysql> use sayohat_agentligi;
Database changed
mysql> show tables;
+-----------------------------+
| Tables_in_sayohat_agentligi |
+-----------------------------+
| mexomonxonalar |
| sayohatchilar |
| sayohatchilar_2 |
+-----------------------------+
UNION,UNION ALL:
Bir nechta so'rovlarni bitta SQL-buyruqqa birlashtirish va
shunga mos ravishda so'rovlar natijalarini birlashtirish uchun UNION kalit so'zidan
foydalaniladi. UNION bilan qo'shilgan so'rovlar bir xil miqdordagi ustunlarni
chiqarishi kerak va ustunlar ma'lumotlari turlari mos bo'lishi kerak. Natijalarni
birlashtirishda takroriy satrlar avtomatik ravishda o'chiriladi. Takroriy satrlarning
o'chirilishining oldini olish uchun UNION so'zining o'rniga UNION ALL
ifodasidan foydalaniladi
mysql> select * from sayohatchilar;
+---------------+---------------+------------+----------------+----------------+----------------------+
| id_sayohatchi | Fam | Ism | telefon_raqami | Manzili | elektron_pochta |
+---------------+---------------+------------+----------------+----------------+----------------------+
| 1 | Shokirov | Asadbek | 2221010 | Bagdod tumani | shokirov@gmail.com |
| 2 | Muxamadaliyev | Abdurahmon | 3002021 | bagdad | abdurahmon@gmail.com |
| 3 | Musajonov | Jasur | 2584547 | Fargona shahri | jasur008@gmail.com |
| 4 | Musajonov | temur | 1452369 | Fargona shahri | temur005gmail.com |
| 5 | Musajonov | Umid | 0 | Fargona shahri | umid005gmail.com |
| 6 | Azimov | Abrorbek | 1564402 | Toshkent sh | abrorbek@gmail.com |
| 7 | Abdumutalibov | Zafarbek | 9945878 | Qoqon sh | zafarbek@gmail.com |
| 8 | Aktamov | Abbos | 2356484 | Bagdod t | aktamov@outloc.com |
+---------------+---------------+------------+----------------+----------------+----------------------+
8 rows in set (0.00 sec)
mysql> select * from sayohatchilar_2;
+---------------+---------------+------------+----------------+----------------+----------------------+
| id_sayohatchi | Fam | Ism | telefon_raqami | Manzili | elektron_pochta |
+---------------+---------------+------------+----------------+----------------+----------------------+
| 1 | Shokirov | Asadbek | 2221010 | Bagdod tumani | shokirov@gmail.com |
| 2 | Muxamadaliyev | Abdurahmon | 3002021 | bagdad | abdurahmon@gmail.com |
| 3 | Musajonov | Jasur | 2584547 | Fargona shahri | jasur008@gmail.com |
| 4 | Musajonov | temur | 1452369 | Fargona shahri | temur005gmail.com |
| 5 | Musajonov | Umid | 0 | Fargona shahri | umid005gmail.com |
| 6 | Azimov | Abrorbek | 1564402 | Toshkent sh | abrorbek@gmail.com |
| 7 | Abdumutalibov | Zafarbek | 9945878 | Qoqon sh | zafarbek@gmail.com |
| 8 | Aktamov | Abbos | 2356484 | Bagdod t | aktamov@outloc.com |
| 9 | Ahrorov | Jasur | 1234569 | Fargona tumani | jasurbek23@gmail.com |
+---------------+---------------+------------+----------------+----------------+----------------------+
mysql> select * from sayohatchilar union all select * from sayohatchilar_2;
+---------------+---------------+------------+----------------+----------------+----------------------+
| id_sayohatchi | Fam | Ism | telefon_raqami | Manzili | elektron_pochta |
+---------------+---------------+------------+----------------+----------------+----------------------+
| 1 | Shokirov | Asadbek | 2221010 | Bagdod tumani | shokirov@gmail.com |
| 2 | Muxamadaliyev | Abdurahmon | 3002021 | bagdad | abdurahmon@gmail.com |
| 3 | Musajonov | Jasur | 2584547 | Fargona shahri | jasur008@gmail.com |
| 4 | Musajonov | temur | 1452369 | Fargona shahri | temur005gmail.com |
| 5 | Musajonov | Umid | 0 | Fargona shahri | umid005gmail.com |
| 6 | Azimov | Abrorbek | 1564402 | Toshkent sh | abrorbek@gmail.com |
| 7 | Abdumutalibov | Zafarbek | 9945878 | Qoqon sh | zafarbek@gmail.com |
| 8 | Aktamov | Abbos | 2356484 | Bagdod t | aktamov@outloc.com |
| 1 | Shokirov | Asadbek | 2221010 | Bagdod tumani | shokirov@gmail.com |
| 2 | Muxamadaliyev | Abdurahmon | 3002021 | bagdad | abdurahmon@gmail.com |
| 3 | Musajonov | Jasur | 2584547 | Fargona shahri | jasur008@gmail.com |
| 4 | Musajonov | temur | 1452369 | Fargona shahri | temur005gmail.com |
| 5 | Musajonov | Umid | 0 | Fargona shahri | umid005gmail.com |
| 6 | Azimov | Abrorbek | 1564402 | Toshkent sh | abrorbek@gmail.com |
| 7 | Abdumutalibov | Zafarbek | 9945878 | Qoqon sh | zafarbek@gmail.com |
| 8 | Aktamov | Abbos | 2356484 | Bagdod t | aktamov@outloc.com |
| 9 | Ahrorov | Jasur | 1234569 | Fargona tumani | jasurbek23@gmail.com |
+---------------+---------------+------------+----------------+----------------+----------------------+
mysql> select * from sayohatchilar union select * from sayohatchilar_2;
+---------------+---------------+------------+----------------+----------------+----------------------+
| id_sayohatchi | Fam | Ism | telefon_raqami | Manzili | elektron_pochta |
+---------------+---------------+------------+----------------+----------------+----------------------+
| 1 | Shokirov | Asadbek | 2221010 | Bagdod tumani | shokirov@gmail.com |
| 2 | Muxamadaliyev | Abdurahmon | 3002021 | bagdad | abdurahmon@gmail.com |
| 3 | Musajonov | Jasur | 2584547 | Fargona shahri | jasur008@gmail.com |
| 4 | Musajonov | temur | 1452369 | Fargona shahri | temur005gmail.com |
| 5 | Musajonov | Umid | 0 | Fargona shahri | umid005gmail.com |
| 6 | Azimov | Abrorbek | 1564402 | Toshkent sh | abrorbek@gmail.com |
| 7 | Abdumutalibov | Zafarbek | 9945878 | Qoqon sh | zafarbek@gmail.com |
| 8 | Aktamov | Abbos | 2356484 | Bagdod t | aktamov@outloc.com |
| 9 | Ahrorov | Jasur | 1234569 | Fargona tumani | jasurbek23@gmail.com |
+---------------+---------------+------------+----------------+----------------+----------------------+
Do'stlaringiz bilan baham: |