Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional SQL Server 2000 Programming
This is the forum to discuss the Wrox book Professional SQL Server 2000 Programming by Robert Vieira; ISBN: 9780764543791
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional SQL Server 2000 Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 5th, 2008, 07:45 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default Querying Two tables

Hello Everyone and thanks for your help in advance. I am working on an application that needs to retireve data from two tables and meld them into one dataset. The two tables are tblPhysicians and tblSpecialists. tblPhysicians has a field License_Number that corresponds to NumericLicenseNumber in tblSpecialists. I want to retrieve the fields First_Name and Last_Name from tblPhysicians and Email address and Specialty from tblSpecialsits for each of the rows in tblSpecialists. I ahve tried numerous ways of joing the tables without success. Any help on this topic would be greatly appreciated.

Reply With Quote
  #2 (permalink)  
Old October 6th, 2008, 12:19 AM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

SELECT P.First_Name, P.Last_Name, S.email, S.specialty
FROM tblPhysicians AS P, tblSpecialists AS S
WHERE P.License_Number = S.License_Number

My guess is that your problem is that you now get
Code:
Joe, Smith, joe@med.com, Respiratory Infections
Joe, Smith, joe@med.com, Hangnails
Joe, Smith, joe@med.com, Halitosis
And what you really *want* is probably something like
Code:
Joe, Smith, joe@med.com, Respiratory Infections
            joe@med.com, Hangnails
            joe@med.com, Halitosis

Or something along those lines. (Though why you would put email address into the specialty table instead of into the main physicians table is beyond me.)

So your problem has nothing to do with the JOIN, it has to do with *PRESENTATION* of the results. You mentioned "dataset", so I would guess you are using ASP.NET.

In any case, if the problem isn't just the join, re-post with some real details.
Reply With Quote
  #3 (permalink)  
Old October 6th, 2008, 07:12 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the assistance. Unfortunately, it is not a presentation issue, rather an issue with joining the tables. Here is where I am at:

SELECT tblFloridaPhysicians.First_Name, tblFloridaPhysicians.Last_Name, tblGastroenterology3.email
FROM tblFloridaPhysicians AS P, tblGastroenterology3 AS S
WHERE tblFloridaPhysicians.License_Number = tblGastroenterology3.License_Number

When I run the query, it returns 1252 items. tblGastroenterology3 has a total of 1525 items, all of which SHOULD be in the 60,000 records in tblFloridaPhysicians (not exactly sure how to query to determine this). So I'm not sure if this is simply records that don't correspond or the query not working correctly.

Thanks again for the assistance.

Reply With Quote
  #4 (permalink)  
Old October 6th, 2008, 02:28 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I'd guess that the records don't correspond.

License_number's in Gastroenterology that are out of date or from other states or mistyped or who knows what.

You can easily determine which are the problem children with another SQL query.

The simplest form:
Code:
SELECT * FROM tblGastroenterology3
WHERE License_Number NOT IN ( SELECT License_Number FROM tblFloridaPhysicians )
You can of course SELECT just some of the fields instead of using * to get all of them.

That should give you 273 records (if your numbers and my math are correct). That's a lot, so good luck sorting this mess out! Because it must surely be a real mess.

*************

p.s.: If you find that the mistake is something consistent (e.g., a prefix or suffix on the License_Number in the gastro table that is not in the main table, or vice versa, then we could figure out an expression to use in the JOIN that would pick them all up, most likely. So look hard to see if you can find a pattern in the mistakes/missing License_Numbers.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Querying against truncated dates John Pennington SQL Server 2000 3 October 17th, 2006 12:55 AM
Querying the NorthWind Database jazzcatone ASP.NET 1.0 and 1.1 Basics 1 March 19th, 2006 04:36 PM
Querying a textfile in QA daniel SQL Server 2000 10 February 1st, 2006 01:51 AM
Querying Recordset with a Loop rabu Access VBA 10 December 14th, 2005 04:49 PM
Querying .csv files aspiring_db_fundu Excel VBA 4 February 25th, 2004 01:01 PM



All times are GMT -4. The time now is 09:40 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.