2016-04-15 138 views
0

当单个表如何获得它们的范围内的记录,我用这个查询得到的范围内记录:连接两个表

SELECT customerId,firstName,lastName FROM customer WHERE customerId BETWEEN min AND max; 

但连接两个表后,怎么能我得到范围内的记录。 在这里,我使用的外键下面,

customer.productId = productDetails.productId 

我的查询:

SELECT customer.custId, customer.productId,GROUP_CONCAT(productDetails.productName) as productName, GROUP_CONCAT(productDetails.productPrice) as productPrice FROM customer, productDetails WHERE customer.productId = productDetails.productId GROUP BY productDetails.productId 
+0

你是什么结果? –

+0

我的结果:custId | productId |产品名称| productPrice | 1000 | 371000 |看,预订| 700,500 | – dev777

回答

1
from what I understand you just need to add an "AND" condition to the query 


WHERE customer.productId = productDetails.productId 
AND customer.custId BETWEEN min and max; 
GROUP BY productDetails.productId 
+0

非常感谢,它为我工作 – dev777