Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Compare 2 tables to exclude records from one of them - part II

Posted on 2012-09-19
10
Medium Priority
?
249 Views
Last Modified: 2012-09-23
For experts to solve this, another thread needs to be read first.

Earlier I asked how to compare 2 tables in order to exclude records from one of them. That was solved (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL_Server_2008/Q_27869482.html).

I later learned that I needed to be able to query and display all the columns available from the subquery - and all data must be contained within the same SQL statement.

The accepted answer was this statement:

select * from tbl01User
where not exists (select null from tbl055PaidMembers where tbl01User.pkIntUserID = tbl055PaidMembers.fkIntUserID and isnull(tbl055PaidMembers.strPaid,0) = '1');

Open in new window


Now - the table called tbl055PaidMembers is the one that I need to be able to query and display.

I hope my question makes sense :)
0
Comment
Question by:jensjakobsen
  • 5
  • 4
10 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 38415321
select * from tbl01User
except
select * from tbl055PaidMembers
0
 
LVL 1

Author Comment

by:jensjakobsen
ID: 38415341
Hi  aneeshattingal.

Thanks for a quick response.

Excactly!

BUT - I need access to all columns from both tables when I query them.
0
 
LVL 13

Expert Comment

by:LIONKING
ID: 38415355
If you just invert the order, will it work?

select * from tbl055PaidMembers
where not exists (select null from tbl01User where tbl01User.pkIntUserID = tbl055PaidMembers.fkIntUserID)
and isnull(tbl055PaidMembers.strPaid,0) = '1';
0
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
LVL 1

Author Comment

by:jensjakobsen
ID: 38415373
Hi Lionking.

Your statement displayed 0 records :(
0
 
LVL 13

Expert Comment

by:LIONKING
ID: 38415389
My query is displaying the records that have strPaid=1 and that "are not" in the tbl01User table.

0 records means that all the records in PaidMembers that have strPaid=1 exist in the table tbl01Users...

What exactly do you want?
0
 
LVL 1

Author Comment

by:jensjakobsen
ID: 38415425
Hi Lionking.

I don't Think I can explain it in further details. Have you read my first thread that I linked to?
0
 
LVL 13

Expert Comment

by:LIONKING
ID: 38415475
Correct me if I'm wrong:

tbl01User - Entire list of members
tbl055PaidMembers - List of members who have paid
tbl055PaidMembers.strPaid (BIT) is an indicator 1=Paid, 0=Not paid

Relationship between tables would be tbl01User.pkIntUserID = tbl055PaidMembers.fkIntUserID

You want to see all the users who have paid? Or not paid?
0
 
LVL 1

Author Comment

by:jensjakobsen
ID: 38415545
Hi Lionking

You are right about the tables and relationship.

StrPaid is of the NCHAR datatype.

I want to see members who hasn't paid and I want to be able to query ALL the columns from both tables so I can display them on web.
0
 
LVL 13

Accepted Solution

by:
LIONKING earned 2000 total points
ID: 38415564
Try

SELECT *
FROM tbl01User LEFT OUTER JOIN tbl055PaidMembers ON
tbl01User.pkIntUserID = tbl055PaidMembers.fkIntUserID
WHERE ISNULL(tbl055PaidMembers.strPaid,'0')='0'

Please note that the columns of table tbl055PaidMembers will display NULL for the users that don't exist in this table.
0
 
LVL 1

Author Comment

by:jensjakobsen
ID: 38426741
Sorry for the delay!

Lionkings last SQL sentence solved the puzzle! Thank you very much!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question