小白 sql 刚学,有个 sql 语句脑子转不过来,大牛进来看看。

2015 年 8 月 26 日
 phantomer
select*from (select user ())a

中的 a 是啥意义?

select*from (select table_name from information_schema.tables where table_schema=database () limit 0,1 )
像这样 mysql 里执行是报错的。

select*from (select table_name from information_schema.tables where table_schema=database () limit 0,1 )a 就可以成功执行,为什么呢?
3777 次点击
所在节点    MySQL
10 条回复
realpg
2015 年 8 月 26 日
别名。。。
nandaye
2015 年 8 月 26 日
Error Code: 1248. Every derived table must have its own alias
必须要有别名 这个是 mysql 的规定 oracle 如果没有别名是不会报错的
helone
2015 年 8 月 26 日
a = AS a
idblife
2015 年 8 月 26 日
别名
不过你为啥这么写,很奇怪
Smilecc
2015 年 8 月 26 日
实际上是 select*from (select user ()) as a
from 后面紧跟的是 table
而使用 select 语句选出来的是一组元组,不能直接查询
所以使用 as 给这个元组重命名为叫 a 的一张表,这样前面的 select 就成立了
ohmycodeape
2015 年 8 月 26 日
别名 连接查询或者子查询时会用到
jhdxr
2015 年 8 月 26 日
目测是在玩注入_(:з」∠)_
RIcter
2015 年 8 月 26 日
@jhdxr 樓主就是大黑闊
Ouyangan
2015 年 8 月 26 日
as nickname
noahliaszn
2016 年 3 月 17 日
木有 alias

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://v2ex.ih06.com/t/216037

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX