Jump to content

Left Join not grabbing data


sniperscope

Recommended Posts

Hello

I have a little problem with left join(yet again)

I want to get all staff name and staff working time.

 

My staff table is:

|  id  |  staff_name |

+-----+----------------+

|  1  | Michael        |

|  2  | Jason          |

 

And schedule table is:

|  id  |  staff_id |  start_time |  end_time |  days |

+-----+-----------+--------------+--------------+-------+

|  1  |  1          | 14:00        |  15:00      | 1334070000

|  2  |  1          | 20:00        |  23:00      | 1334072000

|  3  |  2          | 20:00        |  23:00      | 1334075000

|  4  |  2          | 20:00        |  23:00      | 1334076000

|  5  |  2          | 20:00        |  23:00      | 1334077000

|  6  |  1          | 20:00        |  23:00      | 1334078000

|  7  |  2          | 20:00        |  23:00      | 1334078000

|  8  |  1          | 20:00        |  23:00      | 1334080000

|  9  |  1          | 20:00        |  23:00      | 1334080000

 

I am running this query but it return 0

SELECT g.staff_name, s.start_time, s.end_time FROM staff_master g LEFT JOIN schedule s ON g.id = s.staff_id WHERE s.days >= '1334070000' ORDER BY s.days ASC

What am i trying is to get all staff names and their one week working schedule.

If they are working (lets say) thursday then get his/her start and end time else just echo 00:00

 

Regards

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.