[英]SQL Join between two tables excluding some fields
I have two tables Customer and Beneficiary, the relation between them is ManyToMany, the generated table customers_beneficiaries contains the Id of Beneficiary and the Id of Customer i want to get the list of customers with a given beneficiary_id我有两个表 Customer 和 Beneficiary,它们之间的关系是 ManyToMany,生成的表 customers_beneficiary 包含 Beneficiary 的 Id 和 Customer 的 Id 我想获得具有给定 beneficiary_id 的客户列表
SELECT * from customer c
Full OUTER JOIN customers_beneficiaries cb
ON c.id= cb.customer_id
WHERE cb.beneficiary_id=8;
But the result iam getting contains the two fields of customers_beneficiaries table (customer_id && beneficiary_id) How can i exclude them from the result Thank you.但是我得到的结果包含 customers_beneficiary 表的两个字段 (customer_id && beneficiary_id) 如何从结果中排除它们 谢谢。
Try this:(In case you can change id
column name in customer table to customer_id
)试试这个:(如果您可以将 customer 表中的id
列名称更改为customer_id
)
SELECT c.* from customer c
Full OUTER JOIN customers_beneficiaries cb
USING(customer_id)
WHERE cb.beneficiary_id=8;
USING
Clause is like ON
Clause which takes list of columns on which joining of table has to be done but those columns have to exist in both tables. USING
子句类似于ON
子句,它采用必须在其上进行表连接的列列表,但这些列必须存在于两个表中。 The columns used in join operation appears only once in output. join 操作中使用的列在 output 中只出现一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.