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 |
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2014-05-08 : 22:27:33
|
i have a list of few columns..columnB contains types of fruits..i would like to pull a list of data which doesnt has apple..columnA columnB columnC1 Apple Alice1 Pear John1 Pear Margerat2 Pear Daphine2 Pear John''''i would like not pull those doesnt has apple only, i tried not in method but it come out like this:columnA columnB columnC1 Pear John1 Pear Margerat2 Pear Daphine2 Pear John''''i would like to be like this:columnA columnB columnC2 Pear Daphine2 Pear John''''what method shall i use? |
|
nagino
Yak Posting Veteran
75 Posts |
Posted - 2014-05-09 : 04:41:15
|
[code]SELECT *FROM YourTable SOURCEWHERE NOT EXISTS ( SELECT * FROM YourTable FILTER WHERE FILTER.columnB = 'Apple' AND FILTER.columnA = SOURCE.columnA)[/code]-------------------------------------From JapanSorry, my English ability is limited. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-05-09 : 05:15:48
|
[code]SELECT ColumnA,ColumnB,ColumnCFROM(SELECT *,SUM(CASE WHEN ColumnB = 'Apple' THEN 1 ELSE 0 END) OVER (PARTITION BY ColumnA) AS OccFROM Table)tWHERE Occ=0[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|