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

2015-08-26 10:44:18 +08:00
 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 就可以成功执行,为什么呢?
2881 次点击
所在节点    MySQL
10 条回复
realpg
2015-08-26 10:55:39 +08:00
别名。。。
nandaye
2015-08-26 10:56:06 +08:00
Error Code: 1248. Every derived table must have its own alias
必须要有别名 这个是 mysql 的规定 oracle 如果没有别名是不会报错的
helone
2015-08-26 10:57:45 +08:00
a = AS a
idblife
2015-08-26 10:57:48 +08:00
别名
不过你为啥这么写,很奇怪
Smilecc
2015-08-26 11:01:13 +08:00
实际上是 select*from (select user ()) as a
from 后面紧跟的是 table
而使用 select 语句选出来的是一组元组,不能直接查询
所以使用 as 给这个元组重命名为叫 a 的一张表,这样前面的 select 就成立了
sun2920989
2015-08-26 11:03:46 +08:00
别名 连接查询或者子查询时会用到
jhdxr
2015-08-26 11:45:21 +08:00
目测是在玩注入_(:з」∠)_
RIcter
2015-08-26 11:55:34 +08:00
@jhdxr 樓主就是大黑闊
Ouyangan
2015-08-26 17:03:17 +08:00
as nickname
Alias4ck
2016-03-17 10:40:34 +08:00
木有 alias

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

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

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

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

© 2021 V2EX