Jump to content

LastGoodAirWave

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

LastGoodAirWave's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Okay I got it now. I'm a little slow I guess. I always think of id's as unique. Thanks for your help guys. Posting this as "Solved" Cheers
  2. Hi mikosiko. After some frustration I started thinking more about my table structures and that they could be a poor design. Do you mean something like this? Do I need to change my tables to InnoDB then? I just enabled it on my localhost, but not sure about my server. Employees +------+---------+ | id | name | +------+---------+ | 001 | Joe | | 002 | Sam | | 003 | Mary | | 004 | Bill | | 005 | Jane | +------+---------+ Schedule +-------+------------+ | id | date | +-------+------------+ | 1 | 2011-07-28 | | 2 | 2011-07-29 | +-------+------------+ Employee_Schedule +-------+---------------+----------+ | id | shift_type | employee | +-------+---------------+----------+ | 1 | morn | 003 | | 2 | day | 001 | | 3 | eve | 005 | +-------+---------------+----------+ I'm not sure how the relationship between the dates and the employee_schedule would work. How will I know which date is related to the employee_schedule? Also, wouldn't I need to use a double insert then like this? INSERT INTO schedule (id, date) VALUES('3', '2011-07-30'); INSERT INTO employee_schedule (id, shift_type, employee) VALUES('4', 'day', '005');
  3. Thank you ajlisowski! That works great! I am looking in my O'Reilly "PHP and MySQL" book to try to understand this better. I thought maybe I needed an AS in there somewhere. The book is calling this an attribute alias and says is "useful for complex queries that need to use the same table twice but in different ways." It gives examples but I'll admit I've skipped ahead a little I'm not sure I completely grasp this yet but I now know that it can be done and can dive deeper. I knew that I could use php to store the employees table in an array and then just use the output of sql to display the array, which would give me the same end result I'm looking for, but I really wanted to use MySQL on it's own. I'm assuming it's more efficient using MySQL anyways. Well thank you again! If you think of something else I'd love to hear it. Cheers
  4. So I'm a noob with mysql joins and I'm thinking I'm heading in the wrong direction. I am trying to output a calendar with each shift listing which employee is working it. I can easily output results 002 003 and 005 but obviously want output of Sam Mary and Jane. I could put the employees DB into a PHP array and use that but I'm trying to learn MySQL better, plus this will always be growing. Sometimes you have to dive in to learn. Is my thinking totally wrong on this one? Even a simple answer of "don't use LEFT JOIN, use AS" or whatever will put me in the right direction would be appreciated. I'm not asking you to solve my problem necessarily, I just don't know what to even search for. Any help is appreciated. Thanks so much! MySQL 5.1 Employees +------+---------+ | id | name | +------+---------+ | 001 | Joe | | 002 | Sam | | 003 | Mary | | 004 | Bill | | 005 | Jane | +------+---------+ Schedule +-------+---------------+-----------+---------------+------------+ | id | morning_shift | day_shift | evening_shift | date | +-------+---------------+ ----------+---------------+------------+ | 1 | 002 | 003 | 005 | 2011-07-28 | | 2 | 002 | 001 | 004 | 2011-07-29 | +-------+---------------+-----------+---------------+------------+ This works fine: SELECT name FROM employees LEFT JOIN schedule ON employees.id = schedule.morning_shift WHERE schedule.date = '2011-07-28' How can I do something like this SELECT name FROM employees LEFT JOIN employees ON schedule.morning_shift = employees.id LEFT JOIN employees ON schedule.day_shift = employees.id LEFT JOIN employees ON schedule.evening_shift = employees.id WHERE date = '2011-07-28' error = Not unique table/alias: 'employees'
×
×
  • 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.