inner join returning duplicates
hello i have the following query:
$k=mysql_query("SELECT cat.name_url, cat.id
FROM category cat
WHERE cat.name_url='".$_GET["category"]."' ");
$kRow=mysql_fetch_assoc($k);
$j=mysql_query("SELECT s_cat.name, s_cat.name_url, s_cat.category_id
FROM s_category s_cat
INNER JOIN category cat
ON s_cat.category_id=".$kRow["id"]."
ORDER BY s_cat.name ASC ") or die (mysql_error());
i first fetch a $_GET then use it in my second query but there i get duplicated rows when i fetch the arrays , if instead of using INNER JOIN i build my second query as:
$j=mysql_query("SELECT s_cat.name, s_cat.name_url, s_cat.category_id
FROM s_category s_cat
WHERE s_cat.category_id=".$kRow["i开发者_StackOverflow中文版d"]."
ORDER BY s_cat.name ASC ") or die (mysql_error());
it will work and I wont get duplicates in the fetch row, waht is wrong with my INNER JOIN query?
cheers
syntax for inner join:
SELECT a.name, b.text
FROM a INNER JOIN b ON a.id = b.a_id
WHERE a.name = 'something'
you're missing the "ON a.smth=b.smth" part
use SELECT DISTINCT that'll remove duplicates in your first query
精彩评论