1

I have classroom schedule in an SQL database.

INSERT INTO schedule (date)
  VALUES
  ('2016-05-16 13:00:00'),
  ('2016-05-16 14:00:00'),
  ('2016-05-16 15:00:00'),
  ('2016-05-16 16:00:00'),
  ('2016-05-16 17:00:00'),
  ('2016-05-17 13:00:00'),
  ('2016-05-17 14:00:00'),
  ('2016-05-17 15:00:00'),
  ('2016-05-17 16:00:00'),
  ('2016-05-17 17:00:00'),
  ('2016-05-18 13:00:00'),
  ('2016-05-18 14:00:00'),
  ('2016-05-18 15:00:00'),
  ('2016-05-18 16:00:00'),
  ('2016-05-18 17:00:00'),
  ('2016-05-19 13:00:00'),
  ('2016-05-19 14:00:00'),
  ('2016-05-19 15:00:00'),
  ('2016-05-19 16:00:00'),
  ('2016-05-19 17:00:00');

After I've created the dates in the variable 'date'. I want to insert the accompanying place into another variable called 'place' where to go at that specific time. Something like this

INSERT INTO schedule (place)
  VALUES
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A'),
  ('Room A');

But then I need to make sure that the entries match such that the third entry in 'date' matches the third entry in 'place'. I'm looking for solutions. And if you have an even better all over solution than in this example please let me know :)

1
  • Haven't you mixed INSERT and UPDATE commands?
    – Arvo
    Commented Apr 25, 2016 at 8:05

2 Answers 2

2
INSERT INTO schedule (place, date)
VALUES   ('Room A','2016-05-16 13:00:00')
1

After first insert you have to use update statement. like this:

update schedule 
set place='Room A'

OR you can do this just as one insert:

INSERT INTO schedule (date, place)
  VALUES
  ('2016-05-16 13:00:00','Room A'),
  ('2016-05-16 14:00:00','Room A'),
  ('2016-05-16 15:00:00','Room A'),
  ('2016-05-16 16:00:00','Room A'),
  ('2016-05-16 17:00:00','Room A'),
  ('2016-05-17 13:00:00','Room A'),
  ('2016-05-17 14:00:00','Room A'),
  ('2016-05-17 15:00:00','Room A'),
  ('2016-05-17 16:00:00','Room A'),
  ('2016-05-17 17:00:00','Room A'),
  ('2016-05-18 13:00:00','Room A'),
  ('2016-05-18 14:00:00','Room A'),
  ('2016-05-18 15:00:00','Room A'),
  ('2016-05-18 16:00:00','Room A'),
  ('2016-05-18 17:00:00','Room A'),
  ('2016-05-19 13:00:00','Room A'),
  ('2016-05-19 14:00:00','Room A'),
  ('2016-05-19 15:00:00','Room A'),
  ('2016-05-19 16:00:00','Room A'),
  ('2016-05-19 17:00:00','Room A');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.