Description:
If you try to link one table (say a) to two addictional tables (say b,c) with a join
statement and USING clause,
the first JOIN b USING(matchfldB) works, whilst
the snd one JOIN c USING(matchfldC) doesn't - an error "ERROR 1054 (42S22): Unknown
column" arires.
If you use the ON clause, on the contrary, everything works fine (see example)
How to repeat:
# creates three tables with TRTCA and TRVOC foreign keys in repbug1main
DROP TABLE IF EXISTS `repbug1det1`;
CREATE TABLE `repbug1det1` (
`TRTCA` char(2) NOT NULL default '',
`DxTCA` varchar(40) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `repbug1det1` VALUES ('06','Q.LE TASS.(ARR.QLE.SUP)'),('16','TIPO
COLLO/CONTAINER'),('71','CHILOMETRO');
DROP TABLE IF EXISTS `repbug1det2`;
CREATE TABLE `repbug1det2` (
`TRVOC` varchar(4) NOT NULL default '',
`DxVOC` varchar(30) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `repbug1det2` VALUES ('0011','spese consegna mater.
italia'),('0037','urgenze'),('0304','trasporto contenitori vuoti');
UNLOCK TABLES;
DROP TABLE IF EXISTS `repbug1main`;
CREATE TABLE `repbug1main` (
`CstBill` mediumint(6) unsigned zerofill NOT NULL default '000000',
`TRVOC` varchar(4) NOT NULL default '',
`TRTCA` char(2) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `repbug1main` VALUES
(000064,'0304','16'),(000064,'0011','06'),(000064,'0037','71');
#Using command line client
/*_______________________________________________
mysql> SELECT * FROM test.repbug1main r
-> LEFT JOIN repbug1det1 USING (TRTCA)
-> LEFT JOIN repbug1det2 s ON (r.TRVOC=s.TRVOC)
-> ;
+---------+-------+-------+-------+-------------------------+-------+---------------------
---------+
| CstBill | TRVOC | TRTCA | TRTCA | DxTCA | TRVOC | DxVOC
|
+---------+-------+-------+-------+-------------------------+-------+---------------------
---------+
| 000064 | 0304 | 16 | 16 | TIPO COLLO/CONTAINER | 0304 | trasporto
contenitori vuoti |
| 000064 | 0011 | 06 | 06 | Q.LE TASS.(ARR.QLE.SUP) | 0011 | spese consegna
mater. italia |
| 000064 | 0037 | 71 | 71 | CHILOMETRO | 0037 | urgenze
|
+---------+-------+-------+-------+-------------------------+-------+---------------------
---------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM test.repbug1main r
-> LEFT JOIN repbug1det1 USING (TRTCA)
-> LEFT JOIN repbug1det2 s USING ( TRVOC);
ERROR 1054 (42S22): Unknown column 'test.repbug1det1.TRVOC' in 'on clause'
mysql>
*/
Description: If you try to link one table (say a) to two addictional tables (say b,c) with a join statement and USING clause, the first JOIN b USING(matchfldB) works, whilst the snd one JOIN c USING(matchfldC) doesn't - an error "ERROR 1054 (42S22): Unknown column" arires. If you use the ON clause, on the contrary, everything works fine (see example) How to repeat: # creates three tables with TRTCA and TRVOC foreign keys in repbug1main DROP TABLE IF EXISTS `repbug1det1`; CREATE TABLE `repbug1det1` ( `TRTCA` char(2) NOT NULL default '', `DxTCA` varchar(40) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `repbug1det1` VALUES ('06','Q.LE TASS.(ARR.QLE.SUP)'),('16','TIPO COLLO/CONTAINER'),('71','CHILOMETRO'); DROP TABLE IF EXISTS `repbug1det2`; CREATE TABLE `repbug1det2` ( `TRVOC` varchar(4) NOT NULL default '', `DxVOC` varchar(30) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `repbug1det2` VALUES ('0011','spese consegna mater. italia'),('0037','urgenze'),('0304','trasporto contenitori vuoti'); UNLOCK TABLES; DROP TABLE IF EXISTS `repbug1main`; CREATE TABLE `repbug1main` ( `CstBill` mediumint(6) unsigned zerofill NOT NULL default '000000', `TRVOC` varchar(4) NOT NULL default '', `TRTCA` char(2) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `repbug1main` VALUES (000064,'0304','16'),(000064,'0011','06'),(000064,'0037','71'); #Using command line client /*_______________________________________________ mysql> SELECT * FROM test.repbug1main r -> LEFT JOIN repbug1det1 USING (TRTCA) -> LEFT JOIN repbug1det2 s ON (r.TRVOC=s.TRVOC) -> ; +---------+-------+-------+-------+-------------------------+-------+--------------------- ---------+ | CstBill | TRVOC | TRTCA | TRTCA | DxTCA | TRVOC | DxVOC | +---------+-------+-------+-------+-------------------------+-------+--------------------- ---------+ | 000064 | 0304 | 16 | 16 | TIPO COLLO/CONTAINER | 0304 | trasporto contenitori vuoti | | 000064 | 0011 | 06 | 06 | Q.LE TASS.(ARR.QLE.SUP) | 0011 | spese consegna mater. italia | | 000064 | 0037 | 71 | 71 | CHILOMETRO | 0037 | urgenze | +---------+-------+-------+-------+-------------------------+-------+--------------------- ---------+ 3 rows in set (0.00 sec) mysql> SELECT * FROM test.repbug1main r -> LEFT JOIN repbug1det1 USING (TRTCA) -> LEFT JOIN repbug1det2 s USING ( TRVOC); ERROR 1054 (42S22): Unknown column 'test.repbug1det1.TRVOC' in 'on clause' mysql> */