473,383 Members | 1,837 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.

Complicated Query Trouble

bard777
23
I hope I can describe what I am trying to do here...

I have 3 tables

LC_case
LC_ID
LC_name

LC_loans
LC_LN_ID
LC_LN
LC_LN_2

LC_loss
LS_LN
LS_amt

I am passing a value from a text box called fld_lc_id for LC_ID.

I need something like:

Expand|Select|Wrap|Line Numbers
  1. Select LC_ID, LC_name, LC_LN, LC_LN_2, LS_LN, LS_amt
  2. FROM <BIG FAT JOIN>
  3. WHERE LC_LN_ID = LC_ID AND (LS_LN = LC_LN OR LS_LN = LC_LN_2)
  4.  
What I can't figure out is how to join them. LC_case is the top category that will contain multiple LC_loans. Some of the LC_loss records will match only LC_LN and some will only match LC_LN_2.

Should this be 2 queries with one calling another (which I have no idea how to do) or should it be one query?

Hope this makes at least a little sense.

Thanks in advance.
Aug 5 '08 #1
1 1395
NeoPa
32,556 Expert Mod 16PB
Thank goodness for your WHERE clause. I think I now get what you're after. I assume that it's possible to have a situation where LC_LN AND LC_LN_2 both match records in LC_Loss?

This involves adding the LC_Loss table into the query twice. We use aliases to specify which of the two we're referring to.

I will set up a template which links the tables together for you. You will have to fill in the SELECT fields required later (I'll include some examples to illustrate though).
Expand|Select|Wrap|Line Numbers
  1. SELECT LC.LC_ID,
  2.        LC.LC_Name,
  3.        LN.LC_LN,
  4.        LS1.LS_Amt,
  5.        LN.LC_LN_2,
  6.        LS2.LS_Amt
  7.  
  8. FROM ((LC_Case AS LC INNER JOIN LC_Loans AS LN
  9.   ON   LC.LC_ID=LN.LC_LN_ID) LEFT JOIN LC_Loss AS LS1
  10.   ON   LN.LC_LN=LS1.LS_LN) LEFT JOIN LC_Loss AS LS2
  11.   ON   LN.LC_LN=LS2.LS_LN)
Aug 7 '08 #2

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

Similar topics

10
by: jqq | last post by:
SQL2K on W2Kserver I need some help revamping a rather complicated query. I've given the table and existing query information below. (FYI, changing the database structure is right out.) The...
0
by: apb18 | last post by:
A bit of query plan strangeness. Suppose you have an inheritance tree such that the columns 'ID' and 'field' appear in the top level table, call that table XXX. tables YYY and ZZZ both inherit...
26
by: Jeff | last post by:
Ok gang. Here is something complicated, well, at least to me anyway. Using Access DB I have a table in my DB called members. In that table, I have 2 tables I will be using "username" and...
4
by: Matthew Crouch | last post by:
i suck so much that i don't even know if this is a JOIN or a subquery or who-knows what. Here's the idea: I want to select two things at the same time (form one table) average for columnX and...
3
by: russellhq | last post by:
Hi, I'm fairly new to access and have a little trouble with a crosstab query I've setup. I have a main form where the user selects a project name and below in a subform, a crosstab query is...
5
by: tschulken | last post by:
I have a query where i need to look for a value of a lower level xml element based on the value of a parent element existing first. Here is a simple example of the xml <S3Client> <Buttons>...
0
by: Nick | last post by:
Hi, I have two tables Trade table and Cons table. Records are inserted in both the tables independent of each other. There are fields like Exc_Ref, Qty, Date in both the tables. I need to...
7
by: MarkNeumann | last post by:
I'm coming from a Corel paradox background and moving into an Access environment. So I'm struggling with something that I think is probably way simpler than I'm making it out to be. Access 2007...
1
by: pretzelboy | last post by:
Hi, I last wrote software 13years ago in the pascal, dbase, clipper days. I have recently built a Ubuntu Box and with C++ (and help from the web) setup a serial barcode reader program using Mysql...
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: 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
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?
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.