Reputation: 395
I have two table called
teacher_profile
which have fields like id, centerId, name, study, class etc
And
table center
which have column like id, name, location.
I am trying to get all fields from table teacher_profile and want center name from center table with that query.
$qry="select * from teacher_profile AS q
left join center AS a on a.id = q.centerId
ORDER BY q.id DESC";
$result=mysqli_query($mysqli,$qry);
Its giving me all column from table center as well. I want only name column from it as centerName so I can display it properly in my PHP table. Let me know if someone can help me for achieve it. Thanks
Upvotes: 0
Views: 27
Reputation: 2621
On the query, select statement you can specify which columns you want.
see example
$qry="
SELECT
center.name, teacher_profile.*
FROM
teacher_profile
left join center on teacher_profile.id = center.centerId
ORDER BY
teacher_profile.id DESC
";
$result=mysqli_query($mysqli,$qry);
Upvotes: 0
Reputation: 133380
You can use q.* and a.center uisng alias center_name
$qry="select q.*, a.center center_name from teacher_profile AS q
left join center AS a on a.id = q.centerId
ORDER BY q.id DESC";
$result=mysqli_query($mysqli,$qry);
you can refere the the column using index center_name
echo $row['center_name'];
Upvotes: 2