Multiple Rows to Single Rows
-
I have a query of the form
select * from (
select ...
,...
,...
,a.value_1 open_value_1
,to_number(NULL) close_value_1
from table a
where a.date_col = date_1
union all
select ...
,...
,...
,to_number(NULL) open_value_1
,b.value_1 close_value_1
from table b
where b.date_col = date_2
);If the list of columns represented by the ... is considered a primary key, for the situations where the primary keys are the same I end up with multiple rows
AA BBB CCC open_value_1
AA BBB CCC close_value_1How would I tailor my query to give me only one row instead of two rows. Like this
AA BBB CCC open_value_1 close_value_1
Thanks for any suggestions. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
-
I have a query of the form
select * from (
select ...
,...
,...
,a.value_1 open_value_1
,to_number(NULL) close_value_1
from table a
where a.date_col = date_1
union all
select ...
,...
,...
,to_number(NULL) open_value_1
,b.value_1 close_value_1
from table b
where b.date_col = date_2
);If the list of columns represented by the ... is considered a primary key, for the situations where the primary keys are the same I end up with multiple rows
AA BBB CCC open_value_1
AA BBB CCC close_value_1How would I tailor my query to give me only one row instead of two rows. Like this
AA BBB CCC open_value_1 close_value_1
Thanks for any suggestions. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
Look into Pivot queries. It looks like that may be what you want.
-
I have a query of the form
select * from (
select ...
,...
,...
,a.value_1 open_value_1
,to_number(NULL) close_value_1
from table a
where a.date_col = date_1
union all
select ...
,...
,...
,to_number(NULL) open_value_1
,b.value_1 close_value_1
from table b
where b.date_col = date_2
);If the list of columns represented by the ... is considered a primary key, for the situations where the primary keys are the same I end up with multiple rows
AA BBB CCC open_value_1
AA BBB CCC close_value_1How would I tailor my query to give me only one row instead of two rows. Like this
AA BBB CCC open_value_1 close_value_1
Thanks for any suggestions. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
JOIN
-
I have a query of the form
select * from (
select ...
,...
,...
,a.value_1 open_value_1
,to_number(NULL) close_value_1
from table a
where a.date_col = date_1
union all
select ...
,...
,...
,to_number(NULL) open_value_1
,b.value_1 close_value_1
from table b
where b.date_col = date_2
);If the list of columns represented by the ... is considered a primary key, for the situations where the primary keys are the same I end up with multiple rows
AA BBB CCC open_value_1
AA BBB CCC close_value_1How would I tailor my query to give me only one row instead of two rows. Like this
AA BBB CCC open_value_1 close_value_1
Thanks for any suggestions. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
SELECT ...,...,...,MAX(open_value_1),MAX(close_value_1) FROM
(
--YOUR SELECT QUERY
)A
GROUP BY ...,...,... -
SELECT ...,...,...,MAX(open_value_1),MAX(close_value_1) FROM
(
--YOUR SELECT QUERY
)A
GROUP BY ...,...,...:thumbsup:
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
SELECT ...,...,...,MAX(open_value_1),MAX(close_value_1) FROM
(
--YOUR SELECT QUERY
)A
GROUP BY ...,...,...Perfect. Thanks very much. I knew I needed some grouping to happen and couldn't think of putting some function like max together. It works exactly as I needed it to. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
-
Perfect. Thanks very much. I knew I needed some grouping to happen and couldn't think of putting some function like max together. It works exactly as I needed it to. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
:-D you are welcome