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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:46:32+00:00 2026-06-12T06:46:32+00:00

I’m having a bit of trouble figuring out how to make a query to

  • 0

I’m having a bit of trouble figuring out how to make a query to achieve the following situation. I want a user to be able to view their events and activities (two different tables), along with any events/activities of organizations they belong to sorted by date

Events Table

eventID |  eventTitle   | eventBy   | eventDate
1           Event 1        1          2012/10/11
2           Event 2        2          2012/10/08
3           Event 3        3          2012/10/05

Activities table

postID     |   postTitle  |  postBy  |    postDate
  1            activity 1       1          2012/10/07
  2            activity 2       2          2012/10/09   

orgMembers table

orgID  |  userID
 2             1            //userID 1 is a member of groupID 2

Anyway, I’m trying to get the results to look be the following if userid 1 is viewing the page

 Title            By            Date
Activity 1        1          2012/10/07
Event 2           2          2012/10/08
Activity 2        2          2012/10/09
Event 1           1          2012/10/11

This query results in ONLY my posts only showing, not the organization that I’m a member of too.

select eventTitle as title, eventID as ids, eventBy as byUser, users.username, eventDate as date from events
inner join users on users.userid = events.eventBy
where eventBy in (select distinct g1.userID from orgMembers g1
                 inner join orgMembers g2 on g1.orgID = g2.orgID
                 where g2.userID = '$id') 
                 or eventBy = '$id' 

UNION 

select postTitle as description, postID as ids, postBy as byUser, users.username, postDate as date from posts
inner join users on users.userid = posts.postBy
where postBy in (SELECT distinct g1.userID FROM orgMembers g1
                 inner join orgMembers g2 on g1.orgID = g2.orgID
                 where g2.userID = '$id') 
                 or postBy = '$id'

Order BY date"
  • 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-12T06:46:33+00:00Added an answer on June 12, 2026 at 6:46 am

    using

    WHERE eventby IN 
    

    replace 1 with your user id

    you might want to use UNION to select from 2 tables events and activities

    (select eventInfo as Ttile,eventBy as By, eventDate as Date from Events where Eventby in (SELECT userid FROM groups WHERE groupid = (SELECT groupid FROM groups WHERE userid = 1)))
    UNION
    (select activityInfo as Ttile,activityInfo as By, activityDate as Date from Activities where activityBy in (SELECT userid FROM groups WHERE groupid = (SELECT groupid FROM groups WHERE userid = 1))) Order BY Date

    do the same with activities and the do union and sort

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I want to show the soap response to UIWebview.. my soap response is, <p><img

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.