从另一个表加入一行到另一个表php mysql中的行

时间:2014-02-17 14:14:14

标签: php mysql

我正在使用以下查询来检索数据库中的项目列表

    $statement = $conn->prepare('SELECT * FROM diamondsList WHERE price >= :minPrice AND price <= :maxPrice AND carat >= :minCarat AND carat <= :maxCarat AND cut IN(' . $cut . ') AND clarity IN ('.$clarity.') AND color IN ('. $color.') AND diamondsType IN (' . $type.') ');

diamondsList包含dealerId

我想在diamondsList i-e diamondsList->dealer添加经销商表格。搜索后我发现使用JOIN但不确定如何使用它从diamondList->dealerId

获取经销商行

1 个答案:

答案 0 :(得分:1)

类似......

SELECT diamondsList.*, 
dealer.name
FROM diamondsList
JOIN dealer
on diamondsList.dealerid = dealer.dealerid
WHERE .....