Question : How to write a SQL query to output one record from multiple records in same table

in the example table, is it possible to have a SQL query output the data elements as one line per site, per day?  The common elements are Date, Site, and TranNo


Desired output using example table:

                                IDText                        ID Text                          IDValue
Date                Loc   (from IDKey 919)          (from IDKey 922)            (from IDKey 921)
==========  ===   ================  =================  ================
2010-07-21      579    Supplies                     can opener                      13.7800
2010-07-21      579    Supplies                     green peppers & onion       8.3300
2010-07-24      579    Supplies                     ONIONS                           3.7800
2010-07-24      579    Supplies                     GREEN PEPPERS           2.3700
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Table:
Date        Loc IDKey Field  TranNo  IDText                 IDValue  ValItemKey
==========  ===	===== =====  ======  =====================  =======  ==========
2010-07-21  579	919   19029  1       Supplies		     0.0000  150	
2010-07-21  579	919   19029  2       Supplies		     0.0000  150	
2010-07-21  579	921   19031  1       NULL		    13.7800  NULL	
2010-07-21  579	921   19031  2       NULL		     8.3300  NULL	
2010-07-21  579	922   19030  1       can opener		     0.0000  NULL	
2010-07-21  579	922   19030  2       green peppers & onion   0.0000  NULL	
2010-07-24  579	919   19029  1       Supplies		     0.0000  150	
2010-07-24  579	919   19029  2       Supplies		     0.0000  150	
2010-07-24  579	921   19031  1       NULL		     3.7800  NULL	
2010-07-24  579	921   19031  2       NULL		     2.3700  NULL	
2010-07-24  579	922   19030  1       ONIONS		     0.0000  NULL	
2010-07-24  579	922   19030  2       GREEN PEPPERS	     0.0000  NULL

Answer : How to write a SQL query to output one record from multiple records in same table

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
SELECT
	A.[Date]
	,A.Loc
	,A.IDText
	,C.IDText
	,B.IDValue
FROM 
(SELECT
	[Date]
	,Loc
	,IDKey
	,Field
	,TranNo
	,IDText
	,IDValue
FROM
	MyTable
WHERE IDKey = 919) A
INNER JOIN
(SELECT
	[Date]
	,Loc
	,IDKey
	,Field
	,TranNo
	,IDText
	,IDValue
FROM
	MyTable
WHERE IDKey = 921) B 
	ON A.[Date] = B.[Date] AND A.TranNo = B.TranNo
INNER JOIN
(SELECT
	[Date]
	,Loc
	,IDKey
	,Field
	,TranNo
	,IDText
	,IDValue
FROM
	MyTable
WHERE IDKey = 922) C
	ON A.[Date] = C.[Date] AND A.TranNo = C.TranNo
Random Solutions  
 
programming4us programming4us