Reputation: 1335
I have a table A with the following definition in MySQL
----------------------------------
id c_id t_id
-------------------------------
where c_id references cid on another table B with the following definition
================================================
id cid cname
=================================================
So i am issuing the following query
select group_concat(cname) as list
from A join B using (cid)
where t_id="something";
But I m getting the following error
Unknown column "cid" in from clause
I tried changing it to "c_id", but that doesnt seem to work either..
Any help is appreciated.
Thanks
Upvotes: 13
Views: 16548
Reputation: 1
you can use
select group_concat(cname) as list
from A join B using (c_id)
where t_id="something";
but c_id
is common both table .
Upvotes: 0
Reputation: 21
Both columns need the same name: either c_id or cid Then the using clause will work
Upvotes: 2
Reputation: 171411
USING
in MySQL is just a short form for a standard ON
clause, and only works when the column name is identical in both tables.
From the manual:
The USING(column_list) clause names a list of columns that must exist in both tables.
Instead, do this:
select group_concat(B.cname) as list
from A
inner join B on A.c_id = B.cid
where A.t_id = 'something';
Upvotes: 26