douxie2007
douxie2007
2015-07-22 06:56

如何在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 douwen4125 6年前

    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
    
    点赞 6 评论 复制链接分享
  • dsbgltg159136540 dsbgltg159136540 5年前

    you can give alias using AS to your columns and also to a subquery result

    SELECT s.title as stitle,p.title as ptitle
    FROM og_ratings s 
    INNER JOIN og_companies p
    ON s.client_id = p.id
    WHERE s.id= 115
    
    点赞 4 评论 复制链接分享