Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy and Paste Rows into Same SQL Table with Different Values

I wrote an application for resident housing at a college. In one of the tables (rooms) I have a list of all the rooms and their current/max occupancy. Now, I've added a new column called "semester" and set all of the existing rows to have a semester value of "fall." Now I want copy and paste all of these rows into the table but change the semester value to "spring." The result should be twice as many rows as I started with - half with fall in the semester value and half with spring. Wondering what the best way to accomplish this is?

like image 481
Dave Mackey Avatar asked Mar 12 '12 18:03

Dave Mackey


1 Answers

INSERT INTO rooms
(roomname, current_occupancy, max_occupancy, semester)
SELECT roomname, current_occupancy, max_occupancy,'spring'
FROM rooms
WHERE [semester]='fall'

(assuming names for your room and occupancy columns)

like image 154
squillman Avatar answered Nov 14 '22 04:11

squillman