ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 19th, 2003, 03:04 PM
EiSa EiSa is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Norway
Posts: 184 EiSa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 22 m 24 sec
Reputation Power: 8
More than one JOIN in the Recordset

How do I write a Recordset that needs more than one JOIN?

Example:
Code:
SELECT Table1.ThisID, Table2.ThatID, Table3.AnotherID
FROM Table1 LEFT OUTER JOIN Table2 ON Table1.ThisID = Table2.ThatID Table3 INNER JOIN Table1 Table3.AnotherID = Table1.ThisID
WHERE...


This doesn't work. If it matters, I'm using Access 2000.

I get the error Microsoft JET Database Engine (0x80040E14) Operator missing. If I JOIN only two tables it works fine, but I need to JOIN 4 tables.

If somebody can bring some lights into this I will be very glad.

Last edited by EiSa : September 19th, 2003 at 03:22 PM.

Reply With Quote
  #2  
Old September 19th, 2003, 05:30 PM
Softwaremaker Softwaremaker is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Elbonia with Dilbert and Wally
Posts: 4 Softwaremaker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi EiSa,

There are 2 things you did wrong in your SQL Statement.

1) Always use Brackets around JOINS if there are more than one. The Database needs to know which JOIN to execute first

2) Be aware of ambigious outer joins.

Your SQL Statement should look something like this :

SELECT Table1.ThisID, Table2.ThatID, Table3.AnotherID
FROM (Table1 INNER JOIN Table2 ON Table1.ThisID = Table2.ThatID) INNER JOIN Table3 ON Table2.ThatID = Table3.AnotherID WHERE...

hth

Reply With Quote
  #3  
Old September 20th, 2003, 06:27 AM
EiSa EiSa is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Norway
Posts: 184 EiSa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 22 m 24 sec
Reputation Power: 8
Thank you for your reply, I'm a novice in JOIN. What do you mean with "Be aware of ambigious outer joins"? In this recordset I need to make an outer join because some values appears only sometimes (The plan was to hide/show a link depending on that value, something like If IsNull...).

I have dropped the important values from my recordset, please tell me if this is possible (and yeah, there are faults there in the JOIN'ing).

Code:
SELECT Produkter.ProductID, Produkter.ProduktNavn, Produkter.Aargang, 
Produkter.Produsent, ProdOmtaler.OmtProduktID, Produkter.VareType, 
Produsent.ProducerID, 
Category.CategoryID, SubCategory.IDCategory 
FROM (Produkter LEFT OUTER JOIN ProdOmtaler ON Produkter.ProductID=ProdOmtaler.OmtProduktID) 
(INNER JOIN Produsent ON Produkter.Produsent = Produsent.ProducerID) 
INNER JOIN Category ON Produkter.VareType = CateGory.CategoryID 
ORDER BY Produkter.ProduktNavn

As I said, the OUTER JOIN is important and the only reasen that I try to write this recordset with the use of JOIN. Or is it another solution for my problem?

Thanx anyone

Reply With Quote
  #4  
Old September 20th, 2003, 07:09 PM
Softwaremaker Softwaremaker is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Elbonia with Dilbert and Wally
Posts: 4 Softwaremaker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

I dont know exactly what you are looking for and also the schema of yr DB and tables so its very hard to comment.

However, I think there is something fundamentally flawed with your said SQL Statement. They are not joined properly.

Here is an example of a complex statement. Notice the nested bracket structures and also the operators.

********************
SELECT Table1.ThisID, Table2.ThatID, Table3.AnotherID, Table4.LastID
FROM ((Table1 INNER JOIN Table2 ON Table1.ThisID = Table2.ThatID) INNER JOIN Table3 ON (Table2.ThatID = Table3.AnotherID) AND (Table2.ThatID = Table3.AnotherID)) INNER JOIN Table4 ON (Table2.ThatID = Table4.LastID) AND (Table1.ThisID = Table4.LastID) AND (Table3.AnotherID = Table4.LastID);
**********************

Try using a wizard to generate some of these statements for you so you are more comfortable with JOINS and such. Then u can be on ur way to writing your own more complex joins.

However, please learn to keep JOINS to a minimum. They are complicated to maintain and are very processor-taxing.

You can also try to encapsulate some of these SQL Statements into a separate view or temporary table then link them up. The advantage to this is that they are more readable.

Good luck

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > More than one JOIN in the Recordset


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek