SELECT NULL,*,NULL,NULL中令人困惑的SQL错误 [英] Confusing SQL error in SELECT NULL, *, NULL, NULL
问题描述
背景
我试图解决hackthissite.org中的第四现实任务,但无法弄清楚确切地说,我应该在URL中注入什么SQL来检索电子邮件列表.浪费了几个小时后,我放弃了,看了一种解决方案,它给出了有趣的代码行,该行代码将在选择查询后注入:
The Background
I was trying to solve the fourth realistic mission in hackthissite.org, and couldn't figure out exactly what SQL I should inject into the URL to retrieve the list of emails. After wasting a few hours, I gave up and looked at a solution, which gave this interesting line of code, which was to be injected after a select query:
UNION ALL SELECT NULL, *, NULL, NULL FROM email
我了解这样做的原因以及原因;黑客需要创建一个与合并的查询具有相同列数的查询,并在*周围移动以确保显示电子邮件.那不是我的问题.
I understand what this does and why; the hacker needs to create a query that has the same number of columns as the query it's being merged with, and shifted around the * to make sure the emails are displayed. That's not my question.
问题
我的问题是为什么该代码在MySQL中引发语法错误.经过几次测试,我发现这显然是一个有效的查询:
The Question
My question is why that code throws a syntax error in MySQL. After doing a few tests, I've found that apparently this is a valid query:
SELECT *, NULL, NULL, NULL FROM email
就这样
SELECT NULL, text, NULL, NULL FROM email
但是由于某种原因,它不是:
but for some reason, this isn't:
SELECT NULL, *, NULL, NULL FROM email
并在"*,NULL,来自电子邮件的NULL"附近引发语法错误. 我不明白为什么会这样.似乎查询仅在*是请求的第一列时才有效,而与其他列无关.这是一个错误吗?它是MySQL独有的功能(任务使用了不同的SQL变体)吗?还是我完全误解了?
and throws a syntax error " near '*, NULL, NULL FROM email' ". I fail to understand why this is so. It seems like the query is only valid if * is the first column requested, regardless of what the other columns are. Is this a bug? Is it a feature unique to MySQL (and the mission uses a different variation of SQL)? Or am I misunderstanding this completely?