Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mukhan85
Starting Member
46 Posts |
Posted - 2008-08-08 : 14:29:24
|
| Hi, how can I get only unique rows for ch.Infrastructure_DI?here is the query. The result still contains the same rows.Thank you.select distinct ch.Infrastructure_Change_ID, inc.Request_ID01FROM((select Infrastructure_Change_IDFROM InfrastructureWHERE YEAR(DATEADD(second, Submit_Date, '1969-12-31 8:00:00 PM')) = YEAR(GETDATE()) AND(Change_Request_Status = 11 OR Change_Request_Status = 10) ANDProduct_Cat_Tier_1_2_ = 'Network' AND Product_Cat_Tier_2__2_ = 'RFC' ANDProduct_Cat_Tier_3__2_ NOT IN ('Installation', 'Voice AND Video')) as ch LEFT OUTER JOIN (SELECT DISTINCT (Request_ID02), Request_ID01FROM Association as incWHERE YEAR(DATEADD(second, Submit_Date, '1969-12-31 7:00:00 PM')) = YEAR(GETDATE()) AND Request_ID01 LIKE 'INC%') AS inc ON (ch.Infrastructure_Change_ID = inc.Request_ID02)) |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
mukhan85
Starting Member
46 Posts |
Posted - 2008-08-08 : 14:46:32
|
quote: Originally posted by tkizer Please show us sample data to illustrate your issue.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
Here is sample result set:CRQ000000022553 INC0011 CRQ000000022553 INC0022 CRQ000000022553 INC0012 CRQ000000022510 INC2212 CRQ000000022510 INC3221 AS you can see CRQ000000022553 appeared 3 times and I need to see it only once. with any of INC's . Thank you/ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-08-08 : 14:48:06
|
| Use a group by:select ch.Infrastructure_Change_ID, MAX(inc.Request_ID01) AS Request_ID01FROM((select Infrastructure_Change_IDFROM InfrastructureWHERE YEAR(DATEADD(second, Submit_Date, '1969-12-31 8:00:00 PM')) = YEAR(GETDATE()) AND(Change_Request_Status = 11 OR Change_Request_Status = 10) ANDProduct_Cat_Tier_1_2_ = 'Network' AND Product_Cat_Tier_2__2_ = 'RFC' ANDProduct_Cat_Tier_3__2_ NOT IN ('Installation', 'Voice AND Video')) as ch LEFT OUTER JOIN (SELECT DISTINCT (Request_ID02), Request_ID01FROM Association as incWHERE YEAR(DATEADD(second, Submit_Date, '1969-12-31 7:00:00 PM')) = YEAR(GETDATE()) ANDRequest_ID01 LIKE 'INC%') AS inc ON (ch.Infrastructure_Change_ID = inc.Request_ID02))GROUP BY ch.Infrastructure_Change_IDTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
|
|
|
|
|