Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query problem

Status
Not open for further replies.

sinyce

IS-IT--Management
May 27, 2002
57
0
0
US
I have two tables

Table 1
SALES LNUM AMOUNT
ABC 101 100
ABC 102 200
ABC 103 450
XYZ 674 234

Table2
SALES LIMIT
ABC 4000
XYZ 2000

Trying to write a Query to give me this result:

SALES LNUM AMOUNT LIMIT
ABC 101 100 4000
ABC 102 200
ABC 103 450
XYZ 674 234 2000

Help! This is driving me crazy
 
Write a query (name it "MinLNUM") that gets the lowest LNUM value for each SALES value:

Select SALES, Min(LNUM) as LNUM
From Table1
Group By SALES

Create a query joining your two tables on SALES. Instead of pulling LIMIT directly from Table2, add the MinLNUM query to the query design and join it on SALES to Table1. Create a new field:

LIMIT: IIf(MinLNUM.LNUM=Table1.LNUM,Table2.LIMIT,Null)

Be sure to sort by Table1.SALES and Table1.LNUM

 
Does this work:

Code:
SELECT T1.SALES, LNUM, AMOUNT, LIMIT
FROM TABLE1 T1
LEFT JOIN TABLE2 T2 ON T1.SALES = T2.SALES

Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top