douxie2007 2015-07-22 06:56
浏览 836
已采纳

如何在SQL INNER JOIN中使用AS?

I am new in Mysql. I have multiple tables and i want to join all of them. I use INNER JOIN for this.

"SELECT *
FROM table
               INNER JOIN table2
               ON table.client_id = table2.id

           WHERE table2.id= 113
           ORDER BY table.id DESC
           LIMIT 1 ";

Here i face a problem that i have a column name title in each table. I want to use AS in my command. Like in outlook table there is name of column is TITLE i want to use it as outlook_title. How it is possible?

I want to use echo to print data like this

echo '<h1>' .$row["client"]. '</h1>' ;
echo '<h1>' .$row["name"]. '</h1>' ;
echo '<h1>' .$row["name"]. '</h1>' ;
echo '<h1>' .$row["ation_title"]. '</h1>' ;
echo '<h1>' .$row["look_title"]. '</h1>' ;

Please help me

  • 写回答

2条回答 默认 最新

  • douwen4125 2015-07-22 07:06
    关注

    You said every table, what do I know:>

    Add other columns at your leisure.

    SELECT r.title as rtitle,c.title as ctitle,
    t.title as ttitle,a.title as atitle,o.title as otitle
    FROM og_ratings r 
    INNER JOIN og_companies c
    ON r.client_id = c.id
    INNER JOIN og_rating_types t
    ON r.rating_type_id = t.id
    INNER JOIN og_actions a
    ON r.pacra_action = a.id
    INNER JOIN og_outlooks o
    ON r.pacra_outlook = o.id
    WHERE c.id= 113
    ORDER BY r.id DESC
    LIMIT 1
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 浏览器时间循环 交互事件和延时事件的 优先级与执行问题
  • ¥15 GD模块安装出错,libgd无法正常安装
  • ¥20 求有缘人帮我把笛卡尔坐标系转换为经纬度 有偿
  • ¥15 vue2中使用计算属性
  • ¥50 远程桌面打开Mastercam、没有许可证、物理机打开正常
  • ¥15 ubuntu安装gdal后java读取tif文件报错
  • ¥15 请问lammps怎么做两种金属连接的原子浓度分布图
  • ¥15 求jacquard数据集
  • ¥15 w10部分软件不能联网
  • ¥15 关于安装hbase的问题(操作系统-windows)