Sujith Wayanad
Sujith Wayanad

Reputation: 543

mySQL join with where condition

I have two tables in my db and it is one to many connection with other as shown below

enter image description here

In kvves_units table I will get 'name' from the GET Method

now I want to have all value from the kvves_units and kvves_members according to the name of the kvves_units

I'm using the code something like this

$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");

Upvotes: 0

Views: 62

Answers (3)

Jens
Jens

Reputation: 69440

This is a standard join:

$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'"

Upvotes: 1

Yash
Yash

Reputation: 1436

Try :

$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."'";

You will get your solution.

Upvotes: 0

jay.jivani
jay.jivani

Reputation: 1574

Use this SQL

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

Upvotes: 1

Related Questions