![](/img/trans.png)
[英]MySQL INNER JOIN select only one row from first table if all leads active = 0 and primary_email = Yes in second table
[英]Better way to select all columns from first table and only one column from second table on inner join
表 1 的列:
|a|b|c|d|e|
表 2 的列:
|a|x|y|z|
我只想要 a、b、c、d、e、x。 我只想要表 1 中的“a”列,而不是表 2 中的“a”列。
我有兩張表,其中一列共享一個通用名稱。 如果我使用 Select * 並使用內部聯接,則會返回所有列,包括具有相同名稱的兩列。
我想從第一個表中選擇所有內容,從第二個表中只選擇一列。 現在我正在指定我需要的每一列,這是一個拖累。 有沒有更簡單的方法可以從第一個表中獲取所有內容,而從第二個表中只獲取我想要的一列?
提前致謝。
您需要指定第二個表的列名,如果它與另一個表具有相同的 columnName,則需要在其上提供ALIAS
,
SELECT tb1.*, tb2.x
FROM tableA tb1
INNER JOIN tableB tb2
ON tb1.a = tb2.a
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.