mySQL加入where条件

时间:2014-12-19 07:45:55

标签: mysql sql

我的数据库中有两个表,它与其他表有一对多连接,如下所示

enter image description here

在kvves_units表中,我会得到' name'来自GET方法

现在我希望根据kvves_units

的名称获得kvves_memberskvves_units的所有价值

我正在使用类似的代码

$kvvesDetails = $conn->prepare( "SELECT u.id, u.name, u.phone, u.email, u.address, m.name,    m.designantion, m.phone, m.email, m.imageFROM kvves_units AS u JOIN kvves_members AS m ON m.unit_id = u.id WHERE `name` = $committee");

3 个答案:

答案 0 :(得分:1)

这是标准联接:

$kvvesDetails = $conn->prepare( "SELECT u.id, u.name, u.phone, u.email, u.address, m.name, m.designantion, m.phone, m.email, m.image FROM kvves_units AS u JOIN kvves_members AS m ON m.unit_id = u.id WHERE name = '$committee'"

答案 1 :(得分:1)

  

使用此SQL

select kvves_units.*,kvves_members.* from kvves_units a join kvves_members b where a.name = b.name and a.name = '".$_GET['name']."'

答案 2 :(得分:0)

尝试:

$name = $_GET['name'];
$sql = "Select *from kvves_units as u INNER JOIN kvves_members as m where u.id = m.unit_id and u.name = '".$name."'";

您将获得解决方案。