USING A KEYWORD IN MYSQL

I have table A with the following definition in MySQL

---------------------------------- id c_id t_id ------------------------------- 

where c_id refers to another table B with the following definition

 ================================================ id cid cname ================================================= 

So, I exit the following request

 select group_concat(cname) as list from A join B using (cid) where t_id="something"; 

But I get the following error

 Unknown column "cid" in from clause 

I tried changing it to "c_id", but this does not seem to work.

Any help is appreciated.

thanks

+8
mysql
source share
3 answers

USING in MySQL is just a short form for the standard ON clause and only works when the column name is identical in both tables.

From the manual :

The USING clause (column_list) names the list of columns that must exist in both tables.

Instead, do the following:

 select group_concat(B.cname) as list from A inner join B on A.c_id = B.cid where A.t_id = 'something'; 
+11
source share

Both columns must have the same name: either c_id or cid Then the use clause will work

+2
source share

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 to both tables.

0
source share

All Articles