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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:08:00+00:00 2026-06-12T20:08:00+00:00

I have two (or three, or four…) tables which i want to select all

  • 0

I have two (or three, or four…) tables which i want to select all at once to count the number of entries in all tables together.

for example if i have some tables:
‘news’, ‘articles’, ‘galleries’

in every table i have a row called like “author_id”

now, if i use following select statement:

SELECT *
FROM
news as n, articles as a, galleries as g
WHERE
n.author = 1
AND a.user = 1
AND g.uploader = 1

i only get a result if every table has at least one row with a author (or user or uploader whatever) matching ‘1’
how can i get a result even if one (or two..) tables do not contain ‘1’

  • 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-12T20:08:01+00:00Added an answer on June 12, 2026 at 8:08 pm

    Alternatively, you can combine the results of all table using UNION ALL in a subquery. Then you can now COUNT() the specified Author_ID. The following query will get the total number of records of a specified author_id in ALL tables.

    SELECT COUNT(author_ID)
    FROM
    (
        SELECT userID AS Author_ID FROM news
        UNION ALL
        SELECT user_ID AS Author_ID FROM articles
        UNION ALL
        SELECT UiD AS Author_ID FROM galleries
    ) a
    WHERE a.Author_ID = 1
    

    followup question,

    • how do you want the results to be shown? because this can also be solved by joining the tables.
    • or what is the main table and the referencing table where you want to count the records?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML markup:- <select name=List1 id=l1> <option>One</option> <option>Two</option> <option>Three</option> <option>Four</option> <option>Five</option>
lst = [1,2,3,4] I have hard coded keys ['one','two','three','four','five'] and I want the dictionary
For example i have string one two three four five and I want remove
lets say I have a list like so: ['one','two','three','four','five','six','seven','eight','nine'] and I want to experiment
I have a string like this: $string = 'one/two/three/four'; which I turn it into
We have a rereplace command like the following: <cfoutput> #ReReplaceNoCase(www.one.two.three.four.com,(^www.)|(\..*$),,ALL)# </cfoutput> The idea is
I have a string like this one two three four . I want to
I have markup like this: <p>one two three four</p> And I want to use
Suppose I have a string like this: one two three four five six seven
Let's say I have the following xml: <one> <two> <three> <three> foo </three> <four

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.