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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:25:13+00:00 2026-05-13T12:25:13+00:00

I have to get some data that if possible should be done in one

  • 0

I have to get some data that if possible should be done in one query—if push comes to shove I could always write some PHP logic to do it in two, but I’m thinking that it would be possible to do it in a single query. I don’t know how!

Here is what I want to do:

Generate a listing that displays the total number of posts by an author. Therefore I have to COUNT three different columns from three different tables (reviewsID FROM reviews, featuresID FROM features & newsID FROM news) and then SUM them together to provide a total figure. These will have to be limited with a WHERE userID = THE_ID to have that single user.

At the same time, I want a simpler query that gets a couple things about him/her from the database—userRealName and userLevel.

SELECT userRealName, userLevel FROM user WHERE (userLevel = 'a' OR userLevel = 'e' OR userLevel ='r')

The final table should look something like this:

*userRealName*userLevel*articles*
|------------|---------|--------|
|The user    |e        |87      |
|Another user|r        |34      |

Is this possible?

  • 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-13T12:25:14+00:00Added an answer on May 13, 2026 at 12:25 pm

    This is really hard to do without MySQL here to test it, but I think something like this would work:

    SELECT u.userRealName, u.userLevel, COUNT(t.articleID)
    FROM user u,
    (
        SELECT userID, reviewsID articleID FROM reviews
        UNION ALL
        SELECT userID, featuresID articleID FROM features
        UNION ALL
        SELECT userID, newsID articleID FROM news
    ) t
    WHERE u.userID = t.userID
       AND (u.userLevel = 'a' OR u.userLevel = 'e' OR u.userLevel ='r')
    GROUP BY u.userRealName, u.userLevel
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a winform application that uses some referenced web services to get data.
I have decided that I really need to get some flowcharts for reverse engineering
I have one interesting problem. I must parse mail body (regular expression), get some
Logging can get complicated, quickly. Considering that you have some code, how do you
I'd really like to get into some D3D coding, but I don't have the
I have been having some problems trying to get my PHP running. When I
I have got some code to load an assembly and get all types, which
I'm coding some c# against Active Directory and have tried endlessly to get this
After googling a bit I have found some tips about how to get online
Let's say I have some code like this if(isset($_GET['foo'])) //do something if(isset($_GET['bar'])) //do something

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.