Hi
I have two tables
Here is the query:
select * from timesheet as ts left join activities as activ on activ.activity_id = ts.activity_id and date(dateTimeStamp) = '2013-08-08' and user_id = 1 order by startTime desc;
The results are below. The problem I have is, I would like the activities part of the query to pull results not null values(I dont understand why it does not pull the correct values). I do need the timesheet part of the query to pull null values hence the reason I am using a left join.
Any help appreciated.
[pre]
+--------------+---------+-------------+-----------+------+---------------------+---------------------+----------+---------------------+-------------+-------------------------------------------+------------+-------+------------+
| timesheet_id | user_id | activity_id | account | so | startTime | endTime | comments | dateTimeStamp | activity_id | activity | grouporder | reqso | reqcomment |
+--------------+---------+-------------+-----------+------+---------------------+---------------------+----------+---------------------+-------------+-------------------------------------------+------------+-------+------------+
| 1 | 1 | 1 | Client 1 | 9500 | 2013-08-12 12:30:00 | 2013-08-12 14:00:00 | | 2013-08-08 14:14:00 | 1 | Quotes & Sales orders - Prepare or update | a | y | n |
| 2 | 1 | 1 | Client 2 | 9501 | 2013-08-12 11:24:00 | 2013-08-12 12:00:00 | | 2013-08-08 14:14:00 | 1 | Quotes & Sales orders - Prepare or update | a | y | n |
| 3 | 1 | 13 | Client 3 | 9502 | 2013-08-12 10:00:00 | 2013-08-12 11:00:00 | | 2013-08-08 14:14:00 | 13 | Visuals change requests | b | y | n |
| 14 | 1 | 6 | Client 4 | 9541 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-08 11:55:32 | 6 | Project communication with suppliers | a | y | n |
| 13 | 1 | 5 | Client 5 | 9541 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-08 11:33:32 | 5 | Project communication with client | a | y | n |
| 15 | 1 | 6 | Client 6 | 9541 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-08 12:51:05 | 6 | Project communication with suppliers | a | y | n |
| 32 | 1 | 17 | NULL | NULL | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-12 14:56:23 | NULL | NULL | NULL | NULL | NULL |
| 31 | 1 | 17 | NULL | NULL | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-12 14:54:46 | NULL | NULL | NULL | NULL | NULL |
| 30 | 1 | 17 | NULL | NULL | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-12 14:53:33 | NULL | NULL | NULL | NULL | NULL |
| 29 | 1 | 17 | NULL | NULL | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-12 14:52:54 | NULL | NULL | NULL | NULL | NULL |
| 28 | 1 | 17 | NULL | NULL | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-12 14:48:39 | NULL | NULL | NULL | NULL | NULL |
+--------------+---------+-------------+-----------+------+---------------------+---------------------+----------+---------------------+-------------+-------------------------------------------+------------+-------+------------+
[/pre]
I have two tables
Here is the query:
select * from timesheet as ts left join activities as activ on activ.activity_id = ts.activity_id and date(dateTimeStamp) = '2013-08-08' and user_id = 1 order by startTime desc;
The results are below. The problem I have is, I would like the activities part of the query to pull results not null values(I dont understand why it does not pull the correct values). I do need the timesheet part of the query to pull null values hence the reason I am using a left join.
Any help appreciated.
[pre]
+--------------+---------+-------------+-----------+------+---------------------+---------------------+----------+---------------------+-------------+-------------------------------------------+------------+-------+------------+
| timesheet_id | user_id | activity_id | account | so | startTime | endTime | comments | dateTimeStamp | activity_id | activity | grouporder | reqso | reqcomment |
+--------------+---------+-------------+-----------+------+---------------------+---------------------+----------+---------------------+-------------+-------------------------------------------+------------+-------+------------+
| 1 | 1 | 1 | Client 1 | 9500 | 2013-08-12 12:30:00 | 2013-08-12 14:00:00 | | 2013-08-08 14:14:00 | 1 | Quotes & Sales orders - Prepare or update | a | y | n |
| 2 | 1 | 1 | Client 2 | 9501 | 2013-08-12 11:24:00 | 2013-08-12 12:00:00 | | 2013-08-08 14:14:00 | 1 | Quotes & Sales orders - Prepare or update | a | y | n |
| 3 | 1 | 13 | Client 3 | 9502 | 2013-08-12 10:00:00 | 2013-08-12 11:00:00 | | 2013-08-08 14:14:00 | 13 | Visuals change requests | b | y | n |
| 14 | 1 | 6 | Client 4 | 9541 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-08 11:55:32 | 6 | Project communication with suppliers | a | y | n |
| 13 | 1 | 5 | Client 5 | 9541 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-08 11:33:32 | 5 | Project communication with client | a | y | n |
| 15 | 1 | 6 | Client 6 | 9541 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-08 12:51:05 | 6 | Project communication with suppliers | a | y | n |
| 32 | 1 | 17 | NULL | NULL | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-12 14:56:23 | NULL | NULL | NULL | NULL | NULL |
| 31 | 1 | 17 | NULL | NULL | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-12 14:54:46 | NULL | NULL | NULL | NULL | NULL |
| 30 | 1 | 17 | NULL | NULL | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-12 14:53:33 | NULL | NULL | NULL | NULL | NULL |
| 29 | 1 | 17 | NULL | NULL | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-12 14:52:54 | NULL | NULL | NULL | NULL | NULL |
| 28 | 1 | 17 | NULL | NULL | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | NULL | 2013-08-12 14:48:39 | NULL | NULL | NULL | NULL | NULL |
+--------------+---------+-------------+-----------+------+---------------------+---------------------+----------+---------------------+-------------+-------------------------------------------+------------+-------+------------+
[/pre]
Code:
CREATE TABLE `timesheet` (
`timesheet_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`activity_id` int(10) NOT NULL,
`account` varchar(60) DEFAULT NULL,
`so` int(10) DEFAULT NULL,
`startTime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`endTime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`comments` text,
`dateTimeStamp` datetime NOT NULL,
PRIMARY KEY (`timesheet_id`)
) ENGINE=MyISAM AUTO_INCREMENT=33 DEFAULT CHARSET=latin1
CREATE TABLE `activities` (
`activity_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`activity` varchar(60) NOT NULL,
`grouporder` varchar(5) DEFAULT NULL,
`reqso` char(1) DEFAULT NULL,
`reqcomment` char(1) DEFAULT 'n',
PRIMARY KEY (`activity_id`)
) ENGINE=MyISAM AUTO_INCREMENT=27 DEFAULT CHARSET=latin1