Each view must have its own nickname - an error from a combination, descending MySQL

I want to order one mysql table with two strtotime timestamps from two different columns. I have the following mysql command:

SELECT * FROM ( (SELECT '1' AS `table`, `vid_req_timestamp` AS `timestamp`, `title` FROM `movies` WHERE `vid_req` = '1') UNION (SELECT '2' AS `table`, `ost_req_timestamp` AS `timestamp`, `title` FROM `movies` WHERE `ost_req` = '1') ) ORDER BY `timestamp` DESC 

This gives me an error:

 #1248 - Every derived table must have its own alias 

I want to combine vid_req_timestamp and ost_req_timestamp and make them downstream. And it’s important to know where the timestamp came from (anyway).

+6
source share
1 answer

In this case, the view that requires an alias is the one you selected * with.

Indentation helps make this clearer.

 SELECT * FROM ( (SELECT '1' AS `table`, `vid_req_timestamp` AS `timestamp`, `title` FROM `movies` WHERE `vid_req` = '1') UNION (SELECT '2' AS `table`, `ost_req_timestamp` AS `timestamp`, `title` FROM `movies` WHERE `ost_req` = '1') ) AS `some_table_name_lol_this_is_an_alias` ORDER BY `timestamp` DESC 
+14
source

Source: https://habr.com/ru/post/907520/


All Articles