473,421 Members | 1,703 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,421 software developers and data experts.

conditional joining two table's data in one oledb query, is this possible?

Hello all,
I have two tables, one call Assignments, the other call Grades.
In Assignment, the columns are:
Asn_ID, Asn_Name, Asn_MaxGrade

In Grades, the columns are:
Grade_ID, Grade_Assignment, Grade_Student, Grade_Value

There exist a one-to-many relationship on Asn_ID = Grade_Assignment

My question is this: the grade of a student might not exist in the
grade table, i would like to pull all rows from the assignment table,
and the grade_value from the Grades table IF it exists, otherwise, I
would like to have a new column set to NULL (representing the missing
grade)

I do not know how to achieve this via a single query, thus I have
implemented a somewhat inefficient way in C#:
First, Pull all assignment rows in a select query, load this into a
data table.
Then create a new column in the data table, called Asn_Grades
Then for each row in the table, query the database once again for the
grade entry,
if there is a grade for the record, add it to the data table's new
column,
otherwise, add "-" to the new column
Finally, load this datatable into a dataview for binding.

As you can see, this method requires multiple queries every time the
result needs to be displayed. Is there a single query that can
achieve these?

Regards,

PQ

Sep 4 '07 #1
1 2502
On Sep 3, 11:05 pm, pmous...@gmail.com wrote:
Hello all,
I have two tables, one call Assignments, the other call Grades.
In Assignment, the columns are:
Asn_ID, Asn_Name, Asn_MaxGrade

In Grades, the columns are:
Grade_ID, Grade_Assignment, Grade_Student, Grade_Value

There exist a one-to-many relationship on Asn_ID = Grade_Assignment

My question is this: the grade of a student might not exist in the
grade table, i would like to pull all rows from the assignment table,
and the grade_value from the Grades table IF it exists, otherwise, I
would like to have a new column set to NULL (representing the missing
grade)

I do not know how to achieve this via a single query, thus I have
implemented a somewhat inefficient way in C#:
First, Pull all assignment rows in a select query, load this into a
data table.
Then create a new column in the data table, called Asn_Grades
Then for each row in the table, query the database once again for the
grade entry,
if there is a grade for the record, add it to the data table's new
column,
otherwise, add "-" to the new column
Finally, load this datatable into a dataview for binding.

As you can see, this method requires multiple queries every time the
result needs to be displayed. Is there a single query that can
achieve these?

Regards,

PQ
Use a LEFT JOIN.

Sep 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Ilik | last post by:
Hi all I'm trying to create a summery table of rain data that holds a record for every 0.1mm of rain in the following format: Station Name, Time, Value A, 2002-12-03 14:44:41.000, 0.1 A,...
2
by: James | last post by:
Can anyone please shed some light on the following... I have a framework that uses dynamically created tables, named using an incremental "attribute set ID", as follows: attrdata_1 attrdata_2...
2
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table...
0
by: Paul T. Rong | last post by:
I don't know why that I lost track of the post. I found it from the newsgroup and paste last two posts. Pieter Linden said: "To do this - use conditional formatting..." I didn' work it out....
3
by: Ekhaat | last post by:
Hi I followed the Web Matrix guided tour and came to the "ASP.NET Pages with Data (Microsoft Access)" part. There is really not much you can do wrong there, but for some reason, the INSERT...
20
by: Neil Robbins | last post by:
I am trying to execute a make table query in my vb.net program. The db that I am accessing is an Access 2000 format db. The SQL code that I am using has been cut and pasted from the SQL View having...
4
by: Wayne Wengert | last post by:
I am trying to create a VB.NET Windows application to move some data from a local Access DB table to a table in a SQL Server. The approach I am trying is to open an OLEDB connection to the local...
1
by: Propoflady | last post by:
I have a database that has tables, contact event and last date of contact. Then I have a report where I can print current contact and event. If the last date of contact is less than 3 months...
1
by: KDuncan | last post by:
I have an PSQuery query I've written in Query manager (since I have to use that rather than write the thing in Java, which I'd prefer) and the query joins multiple tables. However, some of those...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.