简体   繁体   English

如何在SQL INNER JOIN中使用AS?

[英]How to use AS in SQL INNER JOIN?

I am new in Mysql. 我是Mysql的新手。 I have multiple tables and i want to join all of them. 我有多个表,我想将它们全部加入。 I use INNER JOIN for this. 我为此使用INNER JOIN。

"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. 我想在命令中使用AS。 Like in outlook table there is name of column is TITLE i want to use it as outlook_title. 就像在Outlook表中一样,列名是TITLE,我想将其用作Outlook_title。 How it is possible? 怎么可能?

I want to use echo to print data like this 我想使用echo来打印这样的数据

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 请帮我

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

you can give alias using AS to your columns and also to a subquery result 您可以使用AS为您的列和subquery结果提供别名

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM