Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2006

Tip: Looking for answers? Try searching our database.

Not in query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 24 Aug 2006 19:47 GMT
Is there an easy way to return all of the items that are not returned from a
query?  I have a working query that returns a group of items, then I want to
query a table for all of the items that do not exist in the first query.
Linda Liu [MSFT] - 25 Aug 2006 03:32 GMT
Hi John,

I think you may set the where clause in the second query to be the contrary
of the where clause in the first query to do this.

For example, we have a table Persons with two fields PersonID and Name in
it. In the first query, we return all the items that the PersonID less than
100. The sql statement is "select * from Persons where PersonID < 100".

Then we could get the rest items in the table by the sql statement "select
* from Persons where PersonID >= 100".

Hope this helps.
If you have any concerns, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
John - 25 Aug 2006 12:23 GMT
I need to explain better.

Say you have three tables, the first is your persons table, the second is
just to hold ID's from the first and third table (to give you a many-to-many
relationship),  and the third table has classes, with 2 fields, classID and
class name.

So one class may have many people and one person may have many classes.  The
second table just links them together, ClassID and PersonID.

So now you have a classID and you want to find all the people who are not in
this class.  You have to query the second table to find who is in the class,
and then you want to query the People table but only return the people not
in you first query.

Is that the best way to do it?  If so, how do you do it.  If not, what is?

> Hi John,
>
[quoted text clipped - 37 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
Pritcham - 25 Aug 2006 14:25 GMT
Hi

Using your example something like the following would get the results
you need:

Select * From person Where PersonID Not In(SELECT PersonClass.PersonID
FROM PersonClass
WHERE (((PersonClass.ClassID)=2)));

This has been run against a mockup DB with 3 tables: Person (PK:
PersonID, Name), Class(PK: ClassID, Classname), PersonClass(PK:
PersonID + ClassID).

Basically the bracketed Select (subquery) is selecting the 'who is in
class 2' results, the first part of the query is finding people in the
person table who are NOT in the results of that (first) query

Hope that helps
Martin

> I need to explain better.
>
[quoted text clipped - 54 lines]
> > This posting is provided "AS IS" with no warranties, and confers no
> > rights.
John - 25 Aug 2006 18:40 GMT
Yeah, I think its working.  Thanks for your help.

> Hi
>
[quoted text clipped - 89 lines]
>> > This posting is provided "AS IS" with no warranties, and confers no
>> > rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.