Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql连接查询_Mysql_Sql - Fatal编程技术网

mysql连接查询

mysql连接查询,mysql,sql,Mysql,Sql,我正在使用以下两个MySQL表: 样本tbl_客户数据集 tbl_产品样本数据集 希望联接两个表 谢谢 这里有一个很好的JOIN的视觉解释,并有一些实际的例子:试试看 SELECT *, CONCAT(tbl_customers.year, tbl_customers.id) as customer_id, product_name as tbl_products.name, customer_id as tbl_customers.id, FROM tbl_customers JOIN t

我正在使用以下两个MySQL表:

样本tbl_客户数据集

tbl_产品样本数据集

希望联接两个表


谢谢

这里有一个很好的JOIN的视觉解释,并有一些实际的例子:

试试看

SELECT *, 
CONCAT(tbl_customers.year, tbl_customers.id) as customer_id,
product_name as tbl_products.name,
customer_id as tbl_customers.id,
FROM tbl_customers 
JOIN tbl_products ON (tbl_customers.product_id = tbl_products.id)
SELECT c.id,c.email,c.phone,CONCAT(c.year,c.id) AS customer_ID,p.name
FROM table_customer c
JOIN table_product p
ON p.id=c.product_id

您错过了customer_idCONCATYEAR和ID partI还错过了ID和name的冗余命名感谢您的帮助,我对mysql连接查询感到困惑,再次感谢。您甚至可以在查询中添加from table name。@seoppc-已添加。但是你打算怎么做?这还不够吗?
SELECT *, 
CONCAT(tbl_customers.year, tbl_customers.id) as customer_id,
product_name as tbl_products.name,
customer_id as tbl_customers.id,
FROM tbl_customers 
JOIN tbl_products ON (tbl_customers.product_id = tbl_products.id)
SELECT c.id,c.email,c.phone,CONCAT(c.year,c.id) AS customer_ID,p.name
FROM table_customer c
JOIN table_product p
ON p.id=c.product_id
select c.id, c.email, c.phone, CONCAT(c.year,' ',c.id), p.name
from tbl_customers c inner join tbl_products p
on c.product_id = p.id