[英]SQL: Select all values from one table in a join while not knowing all column names?
Hello there I wonder if the following is possible (in MySQL): There is a simple query joining two tables: 您好,我想知道以下是否可行(在MySQL中):有一个简单的查询连接两个表:
SELECT * FROM `contact_attending_appointment` AS tcon,`contact` AS tget WHERE tcon.appointment_id = 2 AND tget.id = tcon.contact_id;
This query will return the values of both tables - tcon and tget - joined together. 此查询将返回两个表(tcon和tget)连接在一起的值。 However, I want only to have the columns of ONE table.
但是,我只希望拥有ONE表的列。
Basically in SQL you achieve it like this: 基本上在SQL中你可以像这样实现它:
SELECT col_1,col_2,...,col_n FROM ...
Or you get all the columns with 或者你得到所有的专栏
SELECT * FROM ...
However I would like to have something like (as I do not know the columns of tget by their names) 但是我希望有类似的东西(因为我不知道他们名字的tget列)
SELECT [* from tget] FROM ...
Is there a general solution for this or is this not possible? 是否有一般的解决方案或这是不可能的?
SELECT tget.* FROM contact AS tget ...
The question has already been answered by Rafa. 拉法已经回答了这个问题。 But you seem to be learning SQL.
但你似乎在学习SQL。 The following is a better way of writing your query:
以下是编写查询的更好方法:
SELECT c.*
FROM `contact_attending_appointment` caa INNER JOIN
`contact` c
ON c.id = caa.contact_id
WHERE caa.appointment_id = 2;
The important changes are: 重要的变化是:
on
clause rather than in the where
. on
子句而不是where
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.