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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:52:28+00:00 2026-05-17T14:52:28+00:00

I have a activities page and a statusmessages page for each user. In activities

  • 0

I have a activities page and a statusmessages page for each user.

In activities it contains what the users have done, such as being friends with someone, commented on pictures and so.

users_activities
id | uID | msg | date  

In users_statusmessages, I got the statusmessages, the user creates.

users_statuses
id | uID | message | date

uID is the user´s id.

Now i would like to select both of them and while{} them in one. Where they get sorted by date desc ( as the date in both tables is UNIX timestamp).

So something like WHERE uID = '$userID' ORDER BY date DESC

So example of how i wish it to look:

User: Today is a good day (message) (date: 1284915827) (users_statuses)
User have added as Jack as friend (msg) (date: 1284915811) (users_activities)
User: I have a hard day today (message) (date: 1284915801) (users_statuses)
User have commented on Jacks picture (msg) (date: 1284915776) (users_activities)

How should i do this the right way?

  • 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-17T14:52:28+00:00Added an answer on May 17, 2026 at 2:52 pm

    You need to use the UNION operator:

      SELECT ua.msg, 
             ua.date,
             'activity' AS is_table
        FROM USERS_ACTIVITIES ua
       WHERE ua.uid = '{$userID}'
    UNION ALL
      SELECT us.message, 
             us.date, 
             'status'
        FROM USERS_STATUSES us
       WHERE us.uid = '{$userID}'
    ORDER BY `date`
    

    UNION

    UNION removes duplicates. UNION ALL does not remove duplicates, and is faster for it.

    But the data types at each position in the SELECT must match. In the query provided, you can see that the date column is referenced in the second position. You’d get an error if the column order were reversed between the first and second query.

    The ORDER BY is applied to the result of the UNION’d query in standard SQL. In MySQL, that includes the LIMIT clause. But MySQL also supports putting brackets around the UNION’d queries so you can use ORDER BY & LIMIT before the queries are UNION’d.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 40 activities that do not depend on each other. I want to
I have an application that contains two Activities with <intent-filter> <action android:name=android.intent.action.MAIN/> <category android:name=android.intent.category.LAUNCHER/>
I have 2 activities: Activity1 and Activity2 . In each of this activities there
I have three activities where the first activity is the welcome app page(SavingsGuiderSplashActivity) which
I have a ViewPager with 3 pages. In each page, I would like to
According to the LibGDX web page: Android applications can have multiple activities. Libgdx games
in my app i have three activities named as Home, SignIn and Add Page.
What is the best way to implement a StackOverflow-style Recent Activities page? I have
Context: I have a photography driven site: http://www.camphuawni.com/about-us/activities , and photo tools by each
I have an app that has a lot of activities. In the Settings page

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.