Hello all,
I'm using SS 2000
Based on the following table and data:
CREATE TABLE T (
F1 VARCHAR(1),
F2 INT,
F3 INT)
/* T has no unique key */
/* The data */
INSERT INTO T
SELECT 'A' AS F1, 1 AS F2, 10 AS F3
UNION ALL
SELECT 'B', 2, 12
UNION ALL
SELECT 'B', 3, 11
UNION ALL
SELECT 'A', 4, 10
UNION ALL
SELECT 'B', 3, 11
UNION ALL
SELECT 'A', 0, 0
UNION ALL
SELECT 'B', 2, 5
UNION ALL
SELECT 'D', 6, 7
In the real situation, T is a subquery build from some tables and views. I
cannot easily send the real problem.
I want a query that will return:
- One row for each different F1, no matter which it is.
- Ideally, no temporary table should be created. Only subquery.
- F2 and F3 must come from the same row. So the use of aggregate functions
to retreive each of them cannot be used.
A possible result could be:
F1 F2 F3
---- --------- -----------
A 1 10
B 2 12
D 6 7
How could I do that?
Thanks for your help
Yannick
I'm using SS 2000
Based on the following table and data:
CREATE TABLE T (
F1 VARCHAR(1),
F2 INT,
F3 INT)
/* T has no unique key */
/* The data */
INSERT INTO T
SELECT 'A' AS F1, 1 AS F2, 10 AS F3
UNION ALL
SELECT 'B', 2, 12
UNION ALL
SELECT 'B', 3, 11
UNION ALL
SELECT 'A', 4, 10
UNION ALL
SELECT 'B', 3, 11
UNION ALL
SELECT 'A', 0, 0
UNION ALL
SELECT 'B', 2, 5
UNION ALL
SELECT 'D', 6, 7
In the real situation, T is a subquery build from some tables and views. I
cannot easily send the real problem.
I want a query that will return:
- One row for each different F1, no matter which it is.
- Ideally, no temporary table should be created. Only subquery.
- F2 and F3 must come from the same row. So the use of aggregate functions
to retreive each of them cannot be used.
A possible result could be:
F1 F2 F3
---- --------- -----------
A 1 10
B 2 12
D 6 7
How could I do that?
Thanks for your help
Yannick
Comment