473,487 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SQL Joins

3 New Member
If anyone can help with this I would be most grateful

I have two main tables one containing student ID numbers and another with there personal details such a name, gender and date of birth. I have joined these using a left join and get what I want no problem.

I also have other tables such as visits to the school nurse for example. When I do another left join and the student has visited the school nurse more than once I get more than one record in the new dataset for that student. I knew this would happen however when using a left join but all I want is either one record returned from the school nurse table or even better just a count of how many visits that student has made to the school nurse.

Dim cn As New SqlConnection
Dim cm As New SqlCommand
Dim dr As SqlDataReader
Dim strSQL1 As String

strSQL1 = ""
strSQL1 = strSQL1 & "Select "
strSQL1 = strSQL1 & "CMIS_ADMIN.STUD_ADMIN.STUGROUPS.SetId, "
strSQL1 = strSQL1 & "CMIS_ADMIN.STUD_ADMIN.STUGROUPS.StudentId, "
strSQL1 = strSQL1 & "CMIS_ADMIN.STUD_ADMIN.STUGROUPS.GroupId, "
strSQL1 = strSQL1 & "CMIS_ADMIN.STUD_ADMIN.NSTUPERSONAL.Forename, "
strSQL1 = strSQL1 & "CMIS_ADMIN.STUD_ADMIN.NSTUPERSONAL.Surname, "
strSQL1 = strSQL1 & "CMIS_ADMIN.STUD_ADMIN.NSTUPERSONAL.Stusex, "
strSQL1 = strSQL1 & "CMIS_ADMIN.STUD_ADMIN.NSTUPERSONAL.LeftSchool , "
strSQL1 = strSQL1 & "[JPS_Portal].[dbo].[medical_notes].[Public_note] "

strSQL1 = strSQL1 & "From CMIS_ADMIN.STUD_ADMIN.STUGROUPS "

strSQL1 = strSQL1 & "LEFT JOIN CMIS_ADMIN.STUD_ADMIN.NSTUPERSONAL "
strSQL1 = strSQL1 & "ON CMIS_ADMIN.STUD_ADMIN.STUGROUPS.StudentId = CMIS_ADMIN.STUD_ADMIN.NSTUPERSONAL.StudentId "
strSQL1 = strSQL1 & "AND CMIS_ADMIN.STUD_ADMIN.NSTUPERSONAL.SetId = '" & Session("SetId") & "' "

strSQL1 = strSQL1 & "LEFT JOIN [JPS_Portal].[dbo].[medical_notes] "
strSQL1 = strSQL1 & "ON CMIS_ADMIN.STUD_ADMIN.STUGROUPS.StudentId = [JPS_Portal].[dbo].[medical_notes].StudentId "
strSQL1 = strSQL1 & "AND [JPS_Portal].[dbo].[medical_notes].SetId = '" & Session("SetId") & "' "

strSQL1 = strSQL1 & "Where "
strSQL1 = strSQL1 & "CMIS_ADMIN.STUD_ADMIN.STUGROUPS.GroupId = '" & Request.QueryString("GroupId") & "' "
strSQL1 = strSQL1 & "AND CMIS_ADMIN.STUD_ADMIN.STUGROUPS.setId = '" & Session("SetId") & "' "
strSQL1 = strSQL1 & "AND CMIS_ADMIN.STUD_ADMIN.NSTUPERSONAL.LeftSchool = 'N' "

strSQL1 = strSQL1 & "Order By CMIS_ADMIN.STUD_ADMIN.NSTUPERSONAL.Surname, CMIS_ADMIN.STUD_ADMIN.NSTUPERSONAL.Forename"
Jun 21 '07 #1
1 823
Purple
404 Recognized Expert Contributor
Hi,

How is the visit to the nurse recorded in the table ? is it one row per visit per student ?

Purple
Jun 21 '07 #2

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

Similar topics

6
2070
by: jgalzic | last post by:
Hi, I'm having trouble doing joins correctly on two tables. I've read up a lot about the different types of joins and tried lots of variations on inner, outer, and left joins with no avail....
3
6402
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
4
3975
by: Sri | last post by:
I am writing a download process in which i have a condition where i need to join four tables. Each table have lot of data say around 300000 recs. my question is when i am doing the joins on...
1
4643
by: Prem | last post by:
Hi All Database Gurus, I am trying to write code which will produce all the possible valid queries, given tables and join information for tables. Right now i am just trying to construct all the...
4
4089
by: jbm05 | last post by:
Hi, I'm curious about the computational complexity of a query I have. The query contains multiple nested self left joins, starting with a simple select, then doing a self left join with the...
4
2023
by: michaelnewport | last post by:
Greetings, I like to write my inner joins as below, but someone at work tells me its not as 'performant' as using the 'inner join' statement. Is this true ? Is there a better way to write it...
7
31534
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
2
19711
by: narendra vuradi | last post by:
Hi I have a requirement where in i haev to convert the SQL from Oracle to the one which will run on the SQL server. in the Oracle Query i am doing multiple joins, between some 13 tables. and...
9
11906
by: shapper | last post by:
Hello, I am used to SQL but I am starting to use LINQ. How can I create Left, Right and Inner joins in LINQ? How to distinguish the different joins? Here is a great SQL example:...
36
2456
by: TC | last post by:
I've used Access for many years. Several times, I've encountered a bug which I refer to as the "Vanishing Joins" bug. When it happens, joins vanish randomly from queries. More specifically, all...
0
7137
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,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7349
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
5442
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,...
1
4874
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...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.