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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:53:26+00:00 2026-05-18T19:53:26+00:00

Consider the following tables : account => ID, Login, Pass, Email, Level, IDNum, Name

  • 0

Consider the following tables :

account => ID, Login, Pass, Email, Level, IDNum, Name
records => RID, Status, IDNum, Reason, Type, Amount, Date, SubmitterID

Now I join the tables with the following query:

SELECT account.Name FROM account, records WHERE records.IDNum = account.IDNum

In the query above the Name field would be joined based on matching IDNum, however if I want to get the Name field WHERE account.ID = records.ID and also WHERE records.IDNum = account.IDNum simultaneously, would that be possible?

Question in short, joining the 2 queries below into one :

SELECT account.Name FROM account, records WHERE records.IDNum = account.IDNum
SELECT account.Name FROM account, records WHERE records.SubmitterID = account.ID

I’m probably not clear enough, please check the example data below :

alt text

So obviously the Name field of the first query would return John, and return Chris for the second query. I want to display both names in one query.

  • 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-18T19:53:27+00:00Added an answer on May 18, 2026 at 7:53 pm

    You are actually joinging EVERY rows and then filter out to retains only the one you want. You should instead filter them out right with the join:

    select account.Name
    FROM account
        INNER JOIN records ON (records.IDNum = account.IDNum AND records.SubmitterID = account.ID)

    EDIT: by OP question edit

    Seems you need and OR instead of AND in the above JOIN. Thus:

    select account.Name
    FROM account
        INNER JOIN records ON (records.IDNum = account.IDNum OR records.SubmitterID = account.ID)

    EDIT 2: follow-up to comment by OP

    create table account (id int, IDNum int, Name char(5));
    insert into account values (1, 12345, 'John'), (2, NULL, 'Chris');
    create table records (RID int, IDNum int, SubmitterID int);
    insert into records values (1, 12345, 2);
    select account.Name
    FROM account
        INNER JOIN records ON (records.IDNum = account.IDNum OR records.SubmitterID = account.ID);
    

    yields (with MySQL 5.1.46):

    +-------+
    | Name  |
    +-------+
    | John  |
    | Chris |
    +-------+

    EDIT 3: By OP second comment:

    Something like this?

    select account.Name as byIDNum, NULL bySubmitterID
    from account
        inner join records USING (IDNum)
    union
    select NULL, account.Name
    from account
        inner join records ON (records.SubmitterID = account.ID);
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following tables : account => ID, Login, Pass, Email, Level, IDNum, Name
Consider the following tables; test SQL> desc test; Name Null? Type ----------------------------------------- -------- ----------------------------
Consider the following HTML tables: <table id=myTable1> <tr><td><input type=text id=quantity1 name=quantity1 /></td></tr> <tr><td><input type=text
Consider the following tables: users and tweets user_id name tweet_id user_id tweet spam -----------------
Consider the following tables: department deptid (type:INT) deptname (type: TEXT) hours (type:INT) active (type:BIT)
Consider the following scenario: Tables: Employee (EmpId(PK), Name) TeamMembers(TeamId(PK), EmpId(PK)) Project(ProjId(PK), TeamId) I really
Do splitting fields into multiple tables ever yield faster queries? Consider the following two
Consider following tables: How to skip and take groups from the table? Tried using
Consider following tables in MySQL database: entries: creator_id INT entry TEXT is_expired BOOL other:
Consider the following tables (screenshot of dbml file editor in Visual Studio): http://roosteronacid.com/dbml.png The

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.