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 8841293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:40:45+00:00 2026-06-14T10:40:45+00:00

I am trying to combine these two tables then order it by one column

  • 0

I am trying to combine these two tables then order it by one column (stamp), and aliasing the second table’s id field. I’ve tried joins, merges, but nothing seems to work. I am also trying to group them by the mm

Table note

  id | mm |   stamp    |
==========================
  1  | 5  | 2009-12-11 |
  2  | 33 | 2010-09-10 |
  3  | 22 | 2011-07-08 |
  4  | 1  | 2012-05-06 |

Table note_admin

  id | mm |   stamp    |
==========================
  1  | 5  | 2009-08-15 |
  2  | 5  | 2011-11-11 |
  3  | 5  | 2012-01-08 |
  4  | 35 | 2012-02-06 |

Query I thought would work:

(SELECT * FROM note WHERE mm=5)
UNION
(SELECT id AS a_id, mm, stamp FROM note_admin WHERE mm=5) 
ORDER BY stamp DESC

Expected Result

  id | a_id | mm |   stamp    |
================================
     |   3  | 5  | 2012-01-08 |
     |   2  | 5  | 2011-11-11 |
  1  |      | 5  | 2009-12-11 |
     |   1  | 5  | 2009-08-15 |

I don’t even know if this is possible. I found a way to sort this in PHP but it would be much easier if it can be done in mySQL. Thanks.

  • 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-06-14T10:40:47+00:00Added an answer on June 14, 2026 at 10:40 am

    I think you mean this, note the same 4 column names (not sure about the order by though):

    (SELECT a_id as NULL, note.* FROM note WHERE mm=5) UNION (SELECT id AS a_id, NULL as id, mm, stamp FROM note_admin WHERE mm=5) ORDER BY stamp DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to combine multiple column values into 1 and then label them distinctly
So I have been trying to combine the answers of these two questions: C#
I'm trying to combine two Google App Engine datastore results. Because I then want
trying to save a step and combine these two queries but not sure how
I'm trying to combine two queries in order to determine which aircraft will be
These are the two javascripts that i am trying to combine in the header
I'm trying to combine the codes from these two questions: using jQuery to slideToggle
I've gotta question for you, I'm getting hard times trying to combine two tables,
Can I combine these 2 SQL statements? Currently running 2 queries. Trying to tighten
im trying to combine two images into a single image. unfortunately this has to

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.