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

SQL Joins

If anyone can help with this I would be most grateful

ASP.NET 2.0 and SQL

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 or even better just a count of how many visits a 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"

steve@johnport.derbyshire.sch.uk
Jun 21 '07 #1
2 1030
Hi try with group by or Distinct predicat
Jun 21 '07 #2
Thanks for your prompt reply but it did not work. All I really need is how many records there are in the medical table for each student. I don't need any details just how many records.
Jun 21 '07 #3

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

Similar topics

6
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
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
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
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
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
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
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
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
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
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
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.