minor JOIN problem
Posted: Fri Feb 24, 2012 4:12 am
i'm a newbie with JOINS, but i'm learning.
at the moment I'm having a problem with a query returning duplicate results:
two tables:
for some reason this keeps giving me "David, David," and i cannot figure out why - i've rearranged the query as best i can, and i've tried different JOINS (i'm still learning, sorry)...
can someone show me what's wrong and why i'm getting duplicated results? i'm grateful.
GN
at the moment I'm having a problem with a query returning duplicate results:
two tables:
Code: Select all
a_child
ch_id u_id name
1 2 David
a_subjects
sub_id ch_id sub_name
1 1 English
2 1 History
$result = mysql_query("SELECT c.ch_id, c.name, s.sub_name
FROM a_child c
INNER JOIN a_subjects s ON (c.ch_id = s.ch_id) WHERE c.u_id = 2") or die(mysql_error());
while ($child = mysql_fetch_array($result)) {
echo $child['name'].", ";
}
can someone show me what's wrong and why i'm getting duplicated results? i'm grateful.
GN