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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:27:24+00:00 2026-05-20T07:27:24+00:00

I have two tables, one called pinned and one called unread pinned looks like

  • 0

I have two tables, one called “pinned” and one called “unread”

“pinned” looks like this:

+---------+-------+
|pinned_by|post_id|
+---------+-------+
|2        |3      |
+---------+-------+
|2        |5      |
+---------+-------+

“unread” looks like this:

+---------+-------+
|unread_by|post_id|
+---------+-------+
|2        |5      |
+---------+-------+
|2        |10     |
+---------+-------+

I want to select this from the two tables:

+-------+------+------+
|post_id|unread|pinned|
+-------+------+------+
|3      |0     |1     |
+-------+------+------+
|5      |1     |1     |
+-------+------+------+
|10     |1     |0     |
+-------+------+------+

How can I do this? The values that come through for pinned and unread could be 1/0, 1/null, true/false, etc. I don’t really care as long as I could differentiate which post_id’s came from unread, which came pinned, and which came from both. I’m using MySQL. The _by columns all have 2 in this example, but will vary in the actual implementation. The thought is that a where unread_by=2 and where pinned_by=2 will be included somehow.

Thanks

  • 1 1 Answer
  • 2 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-20T07:27:25+00:00Added an answer on May 20, 2026 at 7:27 am

    Presuming that there is a table of Posts, you can do:

    Select P.post_Id
        , Max( Case When UR.unread_by Is Not Null Then 1 Else 0 End ) As unread
        , Max( Case When P2.pinned_by Is Not Null Then 1 Else 0 End ) As pinned
    From Posts As P
        Left Join Unread As UR
            On UR.post_Id = P.post_Id
        Left Join Pinned As P2
            On P2.post_id = P.post_id
    Group By P.post_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, one called cart and one called items. Now I want
So i'm having this problem. I have two tables (Oracle), one is called Destination
This is a mysql question. I have two tables one called forms and the
I have two tables one called fs_note the other called dumy_fs_note I created after
i have two tables one is called addons and holds information about different addons,
I have two tables: one called Projects, and another called Documents (projects has many
I have two tables, one called countries and one called country. Countries has both
I have two tables one called details and the other called c_details. Both tables
Let's say I have two tables one called Customers and one called CustomerAddresses. Then
I have two tables, one called Users and one called Groups . I also

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.