alagappan r alagappan r - 21 days ago 7
MySQL Question

Get single value using inner join

I have a two tables calldetails and calltype

calldetails table

id calltype isactive
1 1 1
2 1 1
3 1 1


Calltype table

id name isactive
1 mobile internet 1


Expected Result

id name isactive
1 mobile internet 1


but i got i below result

id name isactive
1 mobile internet 1
1 mobile internet 1
1 mobile internet 1


I have used below query

SELECT ct.`name` , ct.`id`
FROM calltype AS ct
INNER JOIN calldetails AS cd ON cd.`isactive` =1
WHERE ct.`isactive` =1
AND ct.`id` = cd.`calltype`
LIMIT 0 , 30


How to get single value using inner join.

Answer

Try with DISTINCT

SELECT DISTINCT ct.`name` , ct.`id`
FROM calltype AS ct
INNER JOIN calldetails AS cd ON cd.`isactive` =1
WHERE ct.`isactive` =1
AND ct.`id` = cd.`calltype`
LIMIT 0 , 30
Comments