473,738 Members | 9,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inner join example

Hi all,

I have a relational database, where all info is kept in separate tables
and just the id's from those tables are stored in one central table
(tblMaster)...
I want to perform a query, so all data from the separate tables is shown
in a view (instead of the reference id's pointing to the separate tables...)
I have some troubles formulating the SQL statement:
I tried:

SELECT tblMaster.*, tblHelper1.*, tblHelper2.*
FROM (tblMaster INNER JOIN tblHelper1 ON
tblMaster.to_id Helper1=tblHelp er1.id) INNER JOIN tblHelper2 ON
tblMaster.to_id Helper2=tblHelp er2.id;

But I don't get any results...

Any suggestions?

Thanks in advance,

Zeff
Apr 11 '07 #1
3 16503
Your query will select all records from these three tables where a
specific Master record has both a helper1 and helper2.

What does this query return?

SELECT *
FROM tblMaster
WHERE to_idHelper1 is not null and to_idHelper2 is not null

If this query returns no records then your issue is that you aren't
doing what you want to do.

Otherwise, what are the structures of the tables? Are the fields
included in the joins of the same data type?

Cheers,
Jason Lepack

On Apr 11, 10:03 am, Zeff <z...@trash.net wrote:
Hi all,

I have a relational database, where all info is kept in separate tables
and just the id's from those tables are stored in one central table
(tblMaster)...
I want to perform a query, so all data from the separate tables is shown
in a view (instead of the reference id's pointing to the separate tables...)
I have some troubles formulating the SQL statement:
I tried:

SELECT tblMaster.*, tblHelper1.*, tblHelper2.*
FROM (tblMaster INNER JOIN tblHelper1 ON
tblMaster.to_id Helper1=tblHelp er1.id) INNER JOIN tblHelper2 ON
tblMaster.to_id Helper2=tblHelp er2.id;

But I don't get any results...

Any suggestions?

Thanks in advance,

Zeff

Apr 11 '07 #2
Dear Jason,

Thanks for your reply. Inner joins show only corresponding records in
all tables...

I found that this shows all coresponding rows:
SELECT tblMaster.*, tbl1.naam1, tbl2.naam2, tbl3.naam3
FROM tbl3 INNER JOIN (tbl2 INNER JOIN (tbl1 INNER JOIN tblMaster ON
tbl1.id_table1= tblMaster.ref_t bl1) ON tbl2.id_table2= tblMaster.ref_t bl2)
ON tbl3.id_table3= tblMaster.ref_t bl3;

Table schemes:
tblMaster(maste r_id,date,ref_t bl1,ref_tbl2, ref_tbl3)
tbl1(id_tbl1, naam1)
tbl2(id_tbl2, naam2)
tbl3(id_tbl3, naam3)

Can you help me with the syntax for LEFT JOINS, to display also non
corresponding records from tblMaster?

Many thanks,

Zeff

Jason Lepack wrote:
Your query will select all records from these three tables where a
specific Master record has both a helper1 and helper2.

What does this query return?

SELECT *
FROM tblMaster
WHERE to_idHelper1 is not null and to_idHelper2 is not null

If this query returns no records then your issue is that you aren't
doing what you want to do.

Otherwise, what are the structures of the tables? Are the fields
included in the joins of the same data type?

Cheers,
Jason Lepack

On Apr 11, 10:03 am, Zeff <z...@trash.net wrote:
>Hi all,

I have a relational database, where all info is kept in separate tables
and just the id's from those tables are stored in one central table
(tblMaster). ..
I want to perform a query, so all data from the separate tables is shown
in a view (instead of the reference id's pointing to the separate tables...)
I have some troubles formulating the SQL statement:
I tried:

SELECT tblMaster.*, tblHelper1.*, tblHelper2.*
FROM (tblMaster INNER JOIN tblHelper1 ON
tblMaster.to_i dHelper1=tblHel per1.id) INNER JOIN tblHelper2 ON
tblMaster.to_i dHelper2=tblHel per2.id;

But I don't get any results...

Any suggestions?

Thanks in advance,

Zeff

Apr 12 '07 #3
What exactly are you trying to accomplish and why must it be done this
way?

You have a many to many relationship, so I would store the data like
this:

(stores the master info)
tbl_master:
master_id
master_date

(stores the name info)
tbl_names:
name_id
name_text

(links a name to a master)
tbl_master_name s:
master_id
name_id

The best way I can think to do it if you can't change your design is
either with nesting subqueries or 3 queries (both work in the same
way).

Create this query and call it step1
SELECT tblMaster.*, tbl1.naam1
FROM tbl1 RIGHT JOIN tblMaster ON tbl1.id_table1 = tblMaster.ref_t bl1;

Create this query and call it step2
SELECT step1.*, tbl2.naam2
FROM step1 LEFT JOIN tbl2 ON step1.ref_tbl2 = tbl2.id_table2;

This is your final result
SELECT step2.*, tbl3.naam3
FROM step2 LEFT JOIN tbl3 ON step2.ref_tbl3 = tbl3.id_table3;

As one big conglomerate query it looks like this:
SELECT step2.*,
tbl3.naam3
FROM (SELECT step1.*,
tbl2.naam2
FROM (SELECT tblMaster.*,
tbl1.naam1
FROM tbl1
RIGHT JOIN tblMaster
ON tbl1.id_table1 = tblMaster.ref_t bl1) AS
step1
LEFT JOIN tbl2
ON step1.ref_tbl2 = tbl2.id_table2) AS step2
LEFT JOIN tbl3
ON step2.ref_tbl3 = tbl3.id_table3;

That will perform what you want, though I think it would be better to
revisit your design.

Cheers,
Jason Lepack

On Apr 12, 3:08 am, Zeff <z...@trash.net wrote:
Dear Jason,

Thanks for your reply. Inner joins show only corresponding records in
all tables...

I found that this shows all coresponding rows:
SELECT tblMaster.*, tbl1.naam1, tbl2.naam2, tbl3.naam3
FROM tbl3 INNER JOIN (tbl2 INNER JOIN (tbl1 INNER JOIN tblMaster ON
tbl1.id_table1= tblMaster.ref_t bl1) ON tbl2.id_table2= tblMaster.ref_t bl2)
ON tbl3.id_table3= tblMaster.ref_t bl3;

Table schemes:
tblMaster(maste r_id,date,ref_t bl1,ref_tbl2, ref_tbl3)
tbl1(id_tbl1, naam1)
tbl2(id_tbl2, naam2)
tbl3(id_tbl3, naam3)

Can you help me with the syntax for LEFT JOINS, to display also non
corresponding records from tblMaster?

Many thanks,

Zeff

Jason Lepack wrote:
Your query will select all records from these three tables where a
specific Master record has both a helper1 and helper2.
What does this query return?
SELECT *
FROM tblMaster
WHERE to_idHelper1 is not null and to_idHelper2 is not null
If this query returns no records then your issue is that you aren't
doing what you want to do.
Otherwise, what are the structures of the tables? Are the fields
included in the joins of the same data type?
Cheers,
Jason Lepack
On Apr 11, 10:03 am, Zeff <z...@trash.net wrote:
Hi all,
I have a relational database, where all info is kept in separate tables
and just the id's from those tables are stored in one central table
(tblMaster)...
I want to perform a query, so all data from the separate tables is shown
in a view (instead of the reference id's pointing to the separate tables...)
I have some troubles formulating the SQL statement:
I tried:
SELECT tblMaster.*, tblHelper1.*, tblHelper2.*
FROM (tblMaster INNER JOIN tblHelper1 ON
tblMaster.to_id Helper1=tblHelp er1.id) INNER JOIN tblHelper2 ON
tblMaster.to_id Helper2=tblHelp er2.id;
But I don't get any results...
Any suggestions?
Thanks in advance,
Zeff- Hide quoted text -

- Show quoted text -

Apr 12 '07 #4

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

Similar topics

3
3355
by: Ike | last post by:
Oh I have a nasty query which runs incredibly slowly. I am running MySQL 4.0.20-standard. Thus, in trying to expedite the query, I am trying to set indexes in my tables. My query requires four inner joins, as follows : SELECT DISTINCT upcards.id,statuskey.status,upcards.firstname,upcards.lastname,originkey.ori gin,associatekey.username,associatekey2.username,upcards.deleted FROM upcards,status,origins,associates INNER JOIN status...
3
6416
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, Employees.LastName, TerritoryID, Employees.EmployeeID, RegionID, ProductID from Employees
1
4010
by: cbielins | last post by:
I'm trying to join a dimension table to a summary table using an inner join. However, I would like to join using a udf that I've created. Example: select ... from fact_table fact inner join schema1.dim_table dim on schema.udf(fact.var1) = dim.var2 I get the error:
6
9315
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: tblEmployees empId -- EmpName -- EmpRole -- EmpManager -------....------------.... ---------....--------------- 1........ dan yella..........1..........2
52
6338
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 variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
12
13191
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
14
2491
by: cjakeman | last post by:
Hi, Solved a little mystery yesterday when I built a form that combined 2 tables with a 1:M relationship and relational integrity. All the correct data was visible on the form but, if I tried to edit any of the fields, the PC bleeped. Seems it was due to the query the form was based on. Again, editing any of the fields of the query caused the PC to bleep.
0
2350
by: katupilar | last post by:
I am writing a tool to interface with a couple of tables in SQL Server 2000. I usually write my queries with an Inner Join to bring in fields from seperate tables and load that to a DataSet. I'm wondering if this way is more efficient then using a DataSet.Relations.Add approach or a combination of the two. When should you use an Inner Join over a Relation within a dataset and vice versa? For example is this possible: ...
11
19970
by: YZXIA | last post by:
Is there any difference between explicit inner join and implicit inner join Example of an explicit inner join: SELECT * FROM employee INNER JOIN department ON employee.DepartmentID = department.DepartmentID
0
9476
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8210
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6751
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
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 we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.