Hi all, I hope your help.
I have this two tables in MySQL:
If tried this query:Code:DROP TABLE IF EXISTS `tbl_1`; CREATE TABLE `tbl_1` ( `id` int(10) NOT NULL AUTO_INCREMENT, `MAC` varchar(3) DEFAULT NULL, `REG` varchar(3) DEFAULT NULL, `CODE` varchar(10) DEFAULT NULL, `NAME` varchar(2) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; INSERT INTO `tbl_1` VALUES ('1', 'AAA', 'TOS', '380264', 'VF'); INSERT INTO `tbl_1` VALUES ('2', 'BBB', 'TOS', '380264', 'VF'); INSERT INTO `tbl_1` VALUES ('3', 'CCC', 'TOS', '380264', 'VF'); INSERT INTO `tbl_1` VALUES ('4', 'DDD', 'TOS', '380264', 'VF'); DROP TABLE IF EXISTS `tbl_2`; CREATE TABLE `tbl_2` ( `ID` int(10) NOT NULL AUTO_INCREMENT, `CODE` varchar(10) DEFAULT NULL, `matr` varchar(10) DEFAULT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; INSERT INTO `tbl_2` VALUES ('1', '380264', '112036');
I have this output:Code:SELECT * FROM tbl_2 WHERE Matr = '112036' AND Code = '380264';
If tried this join query:Code:ID CODE MATR 1 380264 112036
I have this other wrong output:Code:SELECT a.Matr, c.Name, COUNT(*) `number` FROM tbl_2 a JOIN tbl_1 c ON a.Code = c.Code GROUP BY c.Code, Matr, a.Code;
I need this right output:Code:Matr Name number 112036 VF 4
Group for c.Code and a.Code is not sufficient ?Code:Matr Name number 112036 VF 1
Can you help me?
Thanks in advance



Reply With Quote






Bookmarks