[英]How to write a SQL query to get data from several tables?
I need next data from different tables in one report我需要一份报告中来自不同表格的下一个数据
I need to choose all consultants info from consultant.table我需要从consulter.table中选择所有顾问信息
first_name
& last_name
& email
& phone
from passport.table来自passport.table的
first_name
和last_name
以及email
和phone
I have passport_id
in users table我在用户表中有
passport_id
Number of consultant
and his level
from main table of query consultant.table查询consultant.table主表中的顾问
Number of consultant
和level
Use this sql query to get your result:使用此 sql 查询获取结果:
SELECT a.first_name,
a.last_name,
a.email,
a.phone,
b.level,
b.user_id
from passport a
INNER JOIN user c
ON a.id=c.passport_id
INNER JOIN consultant b
ON b.user_id=c.id
Try to do an inner or left join.尝试进行内连接或左连接。 Something like this:
像这样的东西:
SELECT a.first_name, a.last_name, a.email, a.phone, b.* from passport a
LEFT JOIN user b
ON a.id=b.passport_id
I can't see from your screenshot what the field names are for Consultant and Level hence the b.*
to pickup all the fields from that table (I assume it IS on that table?).我无法从您的屏幕截图中看到顾问和级别的字段名称是什么,因此
b.*
可以从该表中提取所有字段(我假设它在该表上?)。 Anyway you can customize this query easily.无论如何,您可以轻松自定义此查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.