Hi i have to write a mysql query i will explain the query how i want to work.
I have two table
A
CREATE TABLE IF NOT EXISTS `A` (
`field1` int(10) NOT NULL AUTO_INCREMENT,
`field2` int(10) NOT NULL,
`field3` int(10) NOT NULL,
`field4` varchar(255) DEFAULT NULL,
`fields5` int(10) NOT NULL,
`field6` varchar(255) NOT NULL,
`field7` varchar(255) NOT NULL,
`field8` int(10) NOT NULL,
`field9` tinyint(1) NOT NULL COMMENT '1=for enabled resource 0= for
disabled resource',
PRIMARY KEY (`field1`);
table B
CREATE TABLE IF NOT EXISTS `estimate_resource_mth` (
`field1` int(10) NOT NULL AUTO_INCREMENT,
`field2` int(10) NOT NULL,
`field3` int(10) NOT NULL,
`field4` int(10) NOT NULL,
PRIMARY KEY (`field1`) ;
There is one to many reference from tableA to tableB that is A.field1 multiple reference to B.table2. Now i will explain what i need to get, i have an id which fetch the data from table A using where condition i need to return this list with the sum of filed4 in tableB(field2 in tableB reference to tableA and it may be a multple row one to many relatio ). How could i got a this data in a single query.
Your description is poor and your generic column names are not very helpful, but if I understand,
tableB.field2referencestableA.field1. In that case, aLEFT JOINwith an aggregateSUM()ontableB.field4will do the job.