Try to search your question here, if you can't find : Ask Any Question Now ?

How do I join two distinct select statements to return any matching results?

HomeCategory: stackoverflowHow do I join two distinct select statements to return any matching results?
john asked 3 weeks ago

I have two tables with account information. Table1 has account types and account numbers. Table2 has account names and account statuses. I want to return a list of accounts from Table1 based on a condition (i.e., AccountNumber = ‘100’ or ‘300’) and join it to records that match conditions in Table2 (i.e.g, AccountStatus = ‘active’).

Table 1

AccountType - School
AccountType - School
AccountType - School
AccountNumber - 100
AccountNumber - 200
AccountNumber - 300

Table 2

AccountName - Tuition Expense
AccountName - Car Expense
AccountName - Food Expense
AccountStatus - Active
AccountStatus - Inactive
AccountStatus - Active

Account Number – 100
Account Number – 200
Account Number – 300

So I can return (Accounts that are ‘100’ or ‘300’ and are ‘Active’):

Table 3

AccountType - School
AccountType - School
AccountNumber - 100 
AccountNumber - 300
AccountName - Tuition Expense
AccountName - Food Expense
AccountStatus - Active
AccountStatus - Active

SELECT Table1.AccountNumber
FROM Table1
WHERE Table1.AccountNumber IN ('100', '300') INNER JOIN
      Table2
      ON Table1.AccountNumber = Table2.AccountName
WHERE Table2.AccountStatus = 'ACTIVE'
1 Answers
Best Answer
Mikhail answered 3 weeks ago
Your Answer

13 + 7 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com