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

Multiple joins (SQL language in Access database, in VB6)

2
Hello,


i'm having some difficulties which You'll solve easily, i guess, so please help me:

I have 3 tables with this structure

1. PROFESOR
id
name
id_subject (that equals FIELD "id" in SUBJECT table)

2. SUBJECT
id
name

3. GRADES
id
id_profesor (equals FIELD "id" in PROFESOR table)
id_subject (equals FIELD "id" in SUBJECT table)
grade


I'm trying to display grades, with subject names and profesor names.

I can display these fields:
"GRADES.grade,SUBJECT.name"
with this SQL query

Expand|Select|Wrap|Line Numbers
  1. SELECT grades.grade, subject.name FROM subject INNER JOIN grades ON grades.id_subject=subject.id WHERE etc etc
Equally for "GRADES.grade,PROFESOR.name", but i cannot combine these three tables.

Hope to be answered :-)

Thank You in advance.

Matej
May 23 '07 #1
3 7251
NeoPa
32,556 Expert Mod 16PB
I don't think you need the id_subject (equals FIELD "id" in SUBJECT table) field in GRADES. It is redundant as the subject can be found from the Profesor link.
Anyway, try :
Expand|Select|Wrap|Line Numbers
  1. SELECT P.Name, S.Name, G.Grade
  2. FROM (Grades AS G INNER JOIN Profesor AS P
  3.   ON G.ID_Profesor=P.ID) INNER JOIN Subject AS S
  4.   ON P.ID_Subject=S.ID
Notice the Grades.ID_Subject field is not required.
May 24 '07 #2
jurkic
2
I don't think you need the id_subject (equals FIELD "id" in SUBJECT table) field in GRADES. It is redundant as the subject can be found from the Profesor link.
Anyway, try :
Expand|Select|Wrap|Line Numbers
  1. SELECT P.Name, S.Name, G.Grade
  2. FROM (Grades AS G INNER JOIN Profesor AS P
  3.   ON G.ID_Profesor=P.ID) INNER JOIN Subject AS S
  4.   ON P.ID_Subject=S.ID
Notice the Grades.ID_Subject field is not required.

Thank You very much for Your answer!

I agree, Grades.ID_Subject is not required at this time, because one profesor teaches just one subject, but it will be possible that one profesore teaches two or more subjects, for example, chemistry, phisycs and biology, so i'll need that identifier.

You've been very helpfull!

Matej
Jun 4 '07 #3
NeoPa
32,556 Expert Mod 16PB
In that case you should remove ID_Subject from the Profesor table. It doesn't makes sense if you can have multiple subjects for a professor ;)
I'm pleased to have helped anyway.
Jun 4 '07 #4

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

Similar topics

9
by: Ed_No_Spam_Please_Weber | last post by:
Hello All & Thanks in advance for your help! Background: 1) tblT_Documents is the primary parent transaction table that has 10 fields and about 250,000 rows 2) There are 9 child tables with...
4
by: Jason_Schaitel | last post by:
I have an application that segregates data into two different databases. Database A has stored procs that perform joins between tables in database A and database B. I am thinking that I have...
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"...
16
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and...
5
by: alingsjtu | last post by:
Hello, every body. When execute dynamic generated multiple OPENQUERY statements (which linkes to DB2) in SQLServer, I always got SQL1040N The maximum number of applications is already connected...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
1
by: Sher Dil | last post by:
07.02.2007 / 2020 hours. I am basically working as an astrologer, and have developed my own software in VB6.0 + Access + Crystal Report 4.6.1.0 What ever I select (I enter code, which...
6
by: GregG | last post by:
Greetings, I've inherited a project which requires the use of multiple Access databases, each containing a dozen or so tables each. I need to perform queries which included relations and results...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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:
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,...
0
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...

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.