473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Multiple instances for query!!

2
I have a couple of tables with test results in both of them. They are pre and post test which need to be displayed by a eventually. The relationship I used for my tables A and B are one to many. Everything gets sorted out by School and Class Number. The problem comes when if a student from table A has taken 2 different test in the same class. The query lists 4 instances for the same student instead of 2. How can I solve this issue??? Is it a problem in the relationships or am I querying the tables wrong! PS. I am using a LEFT JOIN for the tables!
Dec 23 '08 #1
5 2094
ChipR
1,287 Expert 1GB
What are the fields in your tables?
Dec 23 '08 #2
NeoPa
32,556 Expert Mod 16PB
This generally happens when multiple records (A) on the left side of a JOIN match multiple records (B) on the right.

Naturally you get A x B result records.

You need to look at your JOIN (We can't as you didn't include it in the question).
Dec 23 '08 #3
casjr
2
Expand|Select|Wrap|Line Numbers
  1. SELECT Entry.site_cd,
  2.        Entry.site_desc,
  3.        Entry.class_cd,
  4.        Entry.class_desc,
  5.        Entry.lname_a,
  6.        Entry.fname_a,
  7.        Entry.student_cd,
  8.        Entry.lname_b,
  9.        Entry.fname_b,
  10.        Entry.mname,
  11.        Entry.form_cd,
  12.        Entry.rawscr,
  13.        Entry.scalescr,
  14.        Update.form_cd,
  15.        Update.rawscr,
  16.        Update.scalescr
  17. FROM Entry LEFT JOIN [Update]
  18.   ON (Entry.student_cd=Update.student_cd)
  19.  AND (Entry.class_cd=Update.class_cd)
Both tables contain the a set of tests taken at different dates! The pre has to match the post for progress issues! Student_cd is the student ID and class_cd is the class ID.
Dec 23 '08 #4
ChipR
1,287 Expert 1GB
Each record in table A is going to have X rows in the resulting table, where X is the number of matches in table B.
So if a student&class match in 2 rows in table A and 2 rows in table B, you will get 4 rows in the result.
All these are valid results based on the information given, so you may need to add more data to differentiate the 2 tests in the same class for the same student.
Dec 23 '08 #5
NeoPa
32,556 Expert Mod 16PB
Apart from adding the [ CODE ] tags to your post, I also reformatted the SQL because - well, because you hadn't. Free-form SQL is fine for a computer to read. Being human we rather prefer something legible.

What is important here in your SQL, is not so much the specific SQL used (although that may help further down the line) but the structure of the data in each of the two tables. This is what both Chip and I have mentioned already. If you don't want to match multiple records on the left with multiples on the right (I'm guessing not as you complained about too many records in the output) then you need to consider how properly to JOIN the tables within the query (SQL). At this point we don't have enough information about your data to tell you how this should be done. The problem you're reporting certainly indicates that what you are currently using is not correct though.

I hope that helps and Welcome to Bytes!
Dec 23 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Martin V. | last post by:
Hello, Is the multiple instances capability of SQL2K mature enough for a Production system? We're looking at upgrading our hardware but the proposed solution calls for consolidating two...
1
by: Vlad | last post by:
Is there any way to install multiple instances of the same windows service designed with VS.NET 2003? I tried copying the binaries into a separate folder and then copying registry entries for the...
2
by: chairleg | last post by:
Hi, I'm having a problem running a distributed transaction between two linked servers that both have multiple instances of SQL Server installed on them. This is the error message that I...
11
by: Mike | last post by:
Looking to find any information on how to properly configure multiple instances of DB2. This is on Win2k db2 ver 7.2. I am basically looking for information on how the multiple instance settings...
12
by: (Pete Cresswell) | last post by:
I know I can open many instances of a given form, but I've never done it. Now I'm analyzing an application where that seems like just the ticket: Many investment funds, *lots* of data points for...
1
by: Johan | last post by:
If a user happens to open multiple instances of her frontend, what kind of problems can occur? For example, one user reported that she was able to, once or twice, bypass the evaluation...
11
by: Clark Stevens | last post by:
I just finished a WinForms app in VB.NET. I want to allow the user to be able to run multiple instances of the program like you can with Notepad and Wordpad. The way it is now, once I run the...
1
by: Digital Fart | last post by:
hi I want to wrap the access to a sqlite database in an object. So i can create multiple instances of this wrapper with base code to get data out of the sqlite database. But i want to make...
1
by: sunil | last post by:
Hello All. I have written a program as an exe that performs some kind of order processing. The program is first configured and then started manually. I have have multiple instances of this...
6
by: Bugs | last post by:
Does anyone have any recommendations on the best way to create multiple instances of the same class when the final number of instances is unknown? For example, I have a class and based on some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.