MySQL-ning so'roviga "*" nima uchun qo'shiladi?

Nima uchun bu sintaksik xatolarga olib keladi (MySQL 5)?

mysql> select f, blegg.* from blegg limit 1;
+------+------+------+------+
| f    | f    | g    | h    |
+------+------+------+------+
|   17 |   17 |    2 |   17 |
+------+------+------+------+
1 row in set (0.00 sec)

mysql> select f, * from blegg limit 1; -- * is unqualified
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '* 
from blegg limit 1' at line 1

I've looked through the manual but didn't really find anything. Why does select , * ... fail where select , <table>.* ... and select * ... and select *, ... succeed?

4
Nima sababdan tushuntirib berolmayman. Lekin Oracle xuddi shunday narsani biladi.
qo'shib qo'ydi muallif John Weber, manba

3 javoblar

MySQL-dan foydalanish qo'llanmasi bularning barchasini SELECT sintaksisi :

  • A select list consisting only of a single unqualified * can be used as shorthand to select all columns from all tables:

    SELECT * FROM t1 INNER JOIN t2 ...
    
  • tbl_name.* can be used as a qualified shorthand to select all columns from the named table:

    SELECT t1.*, t2.* FROM t1 INNER JOIN t2 ...
    
  • Use of an unqualified * with other items in the select list may produce a parse error. To avoid this problem, use a qualified tbl_name.* reference

    SELECT AVG(score), t1.* FROM t1 ...
    

Hujjatlar, * o'zi tomonidan faqat tanlangan ro'yxatdagi yagona narsa bo'lgan holatda amal qiladi. Biroq, faqatgina * boshqa malumotlari bilan may parse xatosi ishlab chiqaradigan malakali kodni ishlatadi.

MySQL-dan tashqari SQL-92 standarti (eski, lekin Linkable) shunday deydi:

7.9  

         Format

          ::=
              SELECT [  ] 
7
qo'shib qo'ydi
tanlang *, hisob (*) ... muvaffaqiyatli bo'ladi.
qo'shib qo'ydi muallif Matt Fenwick, manba
@Matt tanlov sifatida to'g'ri emas *, f blegg dan f ishlaydi
qo'shib qo'ydi muallif Steve Claridge, manba

Ehtimol, siz bir xil maydonni ikki marta tanlagansiz. Quyidagi so'rovda

select name, * from <...>

* kodi name ni kiritadi, shuning uchun siz ikkinchi marta name ni aniq ko'rsatyapsiz.

Bu ishonchli dalillar emas, chunki quyidagilar haqiqiydir:

select name, name from <...>

va shunga o'xshashdir

select name, users.* from users

ularning har ikkisi bir xil maydonni bir necha marta tanlaydi.

Mumkin emas, bu MySQL-ning sintaksis cheklashidir.

2
qo'shib qo'ydi
Yo'q, shunday emas: count (*) ni tanlang, * dan blegg da ham bajarilmaydi
qo'shib qo'ydi muallif Matt Fenwick, manba
Bu juda katta javob emas, lekin bu sharh uchun juda uzoq/murakkab edi. Agar kimdir aniqroq tushuntirish berilsa, baxtli tarzda o'chiriladi.
qo'shib qo'ydi muallif meagar, manba
Ammo, uning birinchi, ishlaydigan namunasi xuddi shu narsani bajaradi (va chiqishda ikki marta f kiritadi).
qo'shib qo'ydi muallif John Flatness, manba

Lekin

select *, f from blegg 

yaxshi ishlaydi.

Ehtimol, malakasiz * * tanlashda birinchi ibora sifatida paydo bo'lishi kerakmi?

1
qo'shib qo'ydi