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

  • Home
  • SEARCH
  • 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 7593609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:12:45+00:00 2026-05-30T21:12:45+00:00

I wrote this sql statement: SELECT e.id AS event_id, e.title, e.date, e.category, e.place, e.minAge,

  • 0

I wrote this sql statement:

SELECT 
  e.id AS event_id, e.title, e.date, e.category, e.place, e.minAge, e.maxAge,
  p.id, p.name, p.coor, p.nz,
  a.user, a.event, COUNT(a.user) AS attending,
  i.user_id, i.event_id
FROM events AS e
LEFT JOIN attendance a ON a.event = e.id
LEFT JOIN places p ON p.id = e.place
LEFT JOIN invited_friends i ON ( i.event_id = e.id ) AND ( i.user_id = 0 )
GROUP BY e.id
ORDER BY attending DESC

This statement selects events from table events and join some tables. everything is good so far.
I have another table called: invited_friends.

event_id    bigint(20)    
user_id     int(11)   
owner       tinyint(1)

This table stores the user ids that invited to event.

The problem is that not every event is a private event, not every event got invited friends… the way I can tell if event is private or not is the column: category in event table, if it = 4 then it is a private event.

My inner join works, but it ignores all the public events because they have no invited friends.

How can I fix that?

Thanks in advance.

  • 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-30T21:12:46+00:00Added an answer on May 30, 2026 at 9:12 pm
    ...
    FROM events AS e
    LEFT JOIN attendance a ON a.event = e.id
    LEFT JOIN places p ON p.id = e.place
    LEFT JOIN invited_friends i ON ( i.event_id = e.id ) AND ( i.user_id = 0 )
    
    WHERE category != 4  or i.event_id is not null
    
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this SQL server select statement to only return 204 characters and append
When I write an SQL statement, I usually write it like this SELECT COUNT(*)
I wrote a T-SQL Statement similar like this (the original one looks different but
How do I write this SQL statement with Subsonic 2.2 Query Object? SELECT *
I need to write a sql statement like this: SELECT id_segmento AS Segmento, Decode
I've wrote a select from statement for my gaming system but it keeps returning
Trying to find the best way to write this SQL statement. I have a
I wrote a SQL statement, the individual statements work well, but when I combine
I would like to transfer this question to active record: The SQL statement I
I am trying to write a SQL Statement for Interbase. Whats wrong with this

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.