Your ORDER BY should be:
ORDER BY b.priority, c.priority, a.loancode
Cheer
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <kedar@p...>
Subject: [sql_language] Need Help on Query Urgently
: Hi I need help on this urgently...just check out
:
: I got 3 tables
:
: DocType
: DocCode char(2)
: Priority number
:
: Data In Table
: -------------
:
: DocCode - Priority
: LN - 1
: HP - 2
: LE - 3
:
:
: CustType
: CustCode char(1)
: Priority number
:
: Data In Table
: -------------
:
: CustCode - Priority
: C - 1
: I - 2
:
:
: LoanType
: LoanCode
: DocType
: CustType
:
: DocType and CustType are related to each other in LoanType table.
:
: Data In Table
: -------------
: LoanCode - DocType - CustType
:
: 1 - HP - C
: 1 - HP - I
: 1 - LE - I
: 2 - LN - C
: 2 - LN - I
: 3 - HP - C
: 3 - HP - I
: 3 - LE - C
: 4 - HP - C
: 4 - HP - I
: 5 - LN - C
: 5 - LE - C
:
: I want a query which will return a recordset.
: This takes care of priority of CustType and
: then DocType.
:
: As importance is for DocType and in that for
: CustType so the recordset should return the
: following recordset
:
: So the LoanCodes which have LN in them should
: come on Top of all the records,irrespective what
: other DocType it contains. Then the records containing
: HP and then LE. If a LoanCode is having both C & I as
: CustType then Priority should come in picture
: as C = 1 and I =2
:
: LoanCode - DocType - CustType
:
: 2 - LN - C
: 2 - LN - I
: 5 - LN - C
: 5 - LE - C
: 4 - HP - C
: 4 - HP - I
: 1 - HP - C
: 1 - HP - I
: 1 - LE - I
: 3 - HP - C
: 3 - HP - I
: 3 - LE - C
:
: ------------------------------------
:
: I have tried this query
:
: select a.LoanCode,a.DocCode,a.CustType,b.priority,c.priority
: from LoanDocTypeInfo a, DocTypeInfo b, CustTypeInfo c
: where a.DocCode = b.DocCode and a.CustType = c.CustCode
: GROUP BY b.Priority,c.Priority,a.LoanCode,a.DocCode,a.CustType
: ORDER BY b.priority,a.loancode,c.priority
:
: which gives records
:
: LoanCode - DocType - CustType
:
: 2 - LN - C
: 2 - LN - I
: 5 - LN - C
: 1 - HP - C
: 1 - HP - I
: 3 - HP - C
: 3 - HP - I
: 4 - HP - C
: 4 - HP - I
: 1 - LE - I
: 3 - LE - C
: 5 - LE - C
:
: Can You help me on this...kedar@p...