V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
phantomer
V2EX  ›  MySQL

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

  •  
  •   phantomer · 2015-08-26 10:44:18 +08:00 · 2859 次点击
    这是一个创建于 3170 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 就可以成功执行,为什么呢?
    10 条回复    2016-03-17 10:40:34 +08:00
    realpg
        1
    realpg  
       2015-08-26 10:55:39 +08:00
    别名。。。
    nandaye
        2
    nandaye  
       2015-08-26 10:56:06 +08:00
    Error Code: 1248. Every derived table must have its own alias
    必须要有别名 这个是 mysql 的规定 oracle 如果没有别名是不会报错的
    helone
        3
    helone  
       2015-08-26 10:57:45 +08:00
    a = AS a
    idblife
        4
    idblife  
       2015-08-26 10:57:48 +08:00
    别名
    不过你为啥这么写,很奇怪
    Smilecc
        5
    Smilecc  
       2015-08-26 11:01:13 +08:00
    实际上是 select*from (select user ()) as a
    from 后面紧跟的是 table
    而使用 select 语句选出来的是一组元组,不能直接查询
    所以使用 as 给这个元组重命名为叫 a 的一张表,这样前面的 select 就成立了
    sun2920989
        6
    sun2920989  
       2015-08-26 11:03:46 +08:00
    别名 连接查询或者子查询时会用到
    jhdxr
        7
    jhdxr  
       2015-08-26 11:45:21 +08:00
    目测是在玩注入_(:з」∠)_
    RIcter
        8
    RIcter  
       2015-08-26 11:55:34 +08:00 via iPhone
    @jhdxr 樓主就是大黑闊
    Ouyangan
        9
    Ouyangan  
       2015-08-26 17:03:17 +08:00
    as nickname
    Alias4ck
        10
    Alias4ck  
       2016-03-17 10:40:34 +08:00
    木有 alias
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2395 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:25 · PVG 23:25 · LAX 08:25 · JFK 11:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.