MySQL Forums
Forum List  »  Optimizer & Parser

Re: LEFT JOIN WHERE GROUP BY
Posted by: Daniel Flöijer
Date: April 03, 2012 11:22PM

Sorry, create_date belongs to support. I think this should be everything needed:

CREATE TABLE `support` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`statusinternal_id` tinyint(3) unsigned NOT NULL DEFAULT '1',
`create_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9591 DEFAULT CHARSET=latin1 COMMENT='InnoDB free: 11264 kB; InnoDB free: 11264 kB; InnoDB free: 1'

CREATE TABLE `support_internalstatus` (
`id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=latin1

insert into support_internalstatus values
( 1, 'Warranty' ), ( 2, 'Wrong item delivered' ),
(3, 'Exchanged'), ( 4, 'Warranty expired' )

insert into support values
( 1, '2011-01-01 00:00:01' ), ( 1, '2011-03-01 00:00:01' ),
( 2, '2011-01-01 00:00:01' ), ( 2, '2011-02-01 00:00:01' ),
( 2, '2011-02-01 00:00:01' ), ( 2, '2011-04-01 00:00:01' ),
( 3, '2011-01-01 00:00:01' ), ( 3, '2011-02-01 00:00:01' ),
( 3, '2011-02-01 00:00:01' ), ( 3, '2011-02-01 00:00:01' ),
( 4, '2011-02-01 00:00:01' ), ( 4, '2011-02-01 00:00:01' )

I then get something like this with my query:

2, 'Wrong item delivered'
3, 'Exchanged'
2, 'Warranty expired'

What I want is this:

0 (or null), 'Warranty'
2, 'Wrong item delivered'
3, 'Exchanged'
2, 'Warranty expired'

Ie I want all status.name to be present in the result, even if there were no such status during the given create_date interval.

Options: ReplyQuote


Subject
Views
Written By
Posted
3028
April 02, 2012 02:51AM
1292
April 02, 2012 12:04PM
1323
April 02, 2012 01:24PM
1342
April 02, 2012 04:29PM
2008
April 03, 2012 12:50AM
1335
April 03, 2012 05:40PM
Re: LEFT JOIN WHERE GROUP BY
1434
April 03, 2012 11:22PM
1288
April 04, 2012 05:12PM
1042
April 04, 2012 11:10PM
1552
April 05, 2012 08:01PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.