Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7193203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:07:18+00:00 2026-05-28T20:07:18+00:00

I want to order one mysql table by two strtotime timestamps from two different

  • 0

I want to order one mysql table by two strtotime timestamps from two different columns. I’ve got 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 those descending. And it’s important to know where the timestamp came from (somehow).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:07:19+00:00Added an answer on May 28, 2026 at 8:07 pm

    In this case, the derived table that requires an alias is the one that you are SELECTing * from.

    Indentation helps make that 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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've two columns in mysql db table votes : accept and reject i want
How do I sort a MySQL table by two columns? What I want are
I want to make a MySQL to get daily differential values from a table
I want to pass two variable at a time from one page to another
I want to store a playlist of tracks from SoundCloud in a mySQL table.
I have two tables: 1) One is the location table that is kept from
I'm trying to SELECT from two tables and ORDER BY date (a column they
i have three tables, i want to select all data from one of the
Similar to List<> OrderBy Alphabetical Order , we want to sort by one element,
I have one table orders with a foreing key ProductID. I want to show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.