INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Select statement only pulling part of the information.

Select statement only pulling part of the information.

Select statement only pulling part of the information.

(OP)
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]

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

RE: Select statement only pulling part of the information.

(OP)
I have added an attachment image showing the problem. The first example is what I would like to achieve the second is what I am currently getting with my join. Orange headers show the timesheet table and the blue shows the activities table. The green what I would like to see and the red is what I am getting now. Your query will not return row 2.

Thanks again.

RE: Select statement only pulling part of the information.

If you change the LEFT JOIN to INNER JOIN (just as an experiment), do those rows disappear from the result set? If so, then for some reason it doesn't think the activity_id (17 in your first example, 5 in your png) has a match. I'm wondering if the field in the timesheet table needs to be unsigned to match the activities table - I wouldn't expect it to be that picky, but since you're having problems, you could try changing timeshare.activity_id to unsigned and see if it makes a difference.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close