i have multiple tables in a database:
tblOjt
ID studentid courseid companyid addresseeid dateadded datestarted dateended ojthours
1 3 1 1 1 9/25/2013 500
tblStudent
ID lastname firstname middlename course gender renderedhours dateadded archive
3 Dela Cruz Juan Santos BSIT Male 500
tblCourse
ID coursealias coursename hours
1 BSIT Bachelor of Science in Information Technology 500
tblCompany
ID companyname
1 MyCompany
tblAddressee
ID addresseename
1 John dela Cruz
i need to have a SQL statement in which i can get this values:
tableOjt.id tableOJT.surname,firstname, and middlename course companyname addresseename dateadded datestarted dateended ojthours
how will i get this code in SQL using those join methods...im writing it in VB6 ADODC, is this the same syntax in a standard SQL ? thanks
In this case the two tables are joined using the relationship table1.id = table2.id . It is possible to use multiple join statements together to join more than one table at the same time. To do that you add a second INNER JOIN statement and a second ON statement to indicate the third table and the second relationship.
Inner Join is the method of retrieval of data from multiple tables based on a required condition and necessary conditions are that there must be common columns or matched columns between the two tables of the database and the data types of columns must be the same.
You create an inner join by dragging a field from one data source to a field on another data source. Access displays a line between the two fields to show that a join has been created. The names of the tables from which records are combined.
The most common way of joining three tables goes something like this: SELECT * FROM Table1 INNER JOIN Table2 ON Condition INNER JOIN Table3 ON Condition; This uses an inner join, but you can specify your desired join type as with any other join. You can also combine join types if required (example below).
If you are writing a query against an Access database backend, you need to use the following join syntax:
select
t1.c1
, t2.c2
, t3.c3
, t4.c4
from ((t1
inner join t2 on t1.something = t2.something)
inner join t3 on t2.something = t3.something)
inner join t4 on t3.something = t4.something
The table and column names aren't important here, but the placement of the parentheses is. Basically, you need to have n - 2 left parentheses after the from
clause and one right parenthesis before the start of each new join
clause except for the first, where n is the number of tables being joined together.
The reason is that Access's join syntax supports joining only two tables at a time, so if you need to join more than two you need to enclose the extra ones in parentheses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With