Reputation: 801
I am tackling a problem where I have to convert Table 1 to Table 2 using mysql
Table 2 structure is only define. How can I go about this? I have tried using union statement but am unable to convert Has on Monday to Monday as the column value
Upvotes: 0
Views: 22
Reputation: 49089
You should write your query as this:
SELECT student, class, 'Monday' AS weekday
FROM table_1
WHERE has_on_monday='T'
UNION ALL
SELECT student, class, 'Tuesday' AS weekday
FROM table_1
WHERE has_on_tuesday='T'
UNION ALL
....
if you want to insert the result to table_2, use a INSERT query:
INSERT INTO table_2 (student, class, weekday)
SELECT ...the select query above...
Upvotes: 2