Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Filter results in select

Posted on 2011-03-14
7
Medium Priority
?
305 Views
Last Modified: 2012-05-11
select * from table

name1  4 o
name1  5 x
name1  3 x
name2  3 x
name3  2 x

I have above results in that name1 have values 3,4 and 5
I want to get the result as below where where the flag 'O' has been taken in case of multiple values for same name.here it is name1

name1  4 o
name2  3 x
name3  2 x

Please help!
0
Comment
Question by:PeteEngineer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Accepted Solution

by:
CarlsbergFTW earned 668 total points
ID: 35128002
select * from table where upper(name1) like ('% o')

The data you provided is consisted in 1 or more tables ?

please post more details if this is not what you're looking for.
0
 
LVL 3

Assisted Solution

by:CarlsbergFTW
CarlsbergFTW earned 668 total points
ID: 35128024
select * from table where upper(name1) like upper('% o')
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 332 total points
ID: 35128033
col1 change it to your name of name column and col3 is 'o' and 'x'

try this

select * from tablename
where col1 in (select col1 from tablename
Group by count(*)>1)
and col3 = 'o'
Union
select * from tablename
where col1 in (select col1 from tablename
Group by count(*)= 1)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 332 total points
ID: 35128036
this might do:
select t.*
  from (select name_field, number_field, flag_field
             , row_number() over (partition by name_field order by case when flag_field = 'o' then 0 else 1 end) rn
          from yourtable 
        ) t
where t.rn = 1

Open in new window

0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 35128037
no only one table... name1 is a value not a coulmn name  and o is a value in another column
0
 
LVL 7

Assisted Solution

by:mkobrin
mkobrin earned 332 total points
ID: 35128070
please supplt the column names and then we can help you with the query
0
 
LVL 30

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 336 total points
ID: 35128089
I think you're having three columns. But see how hard that is to tell, as CarlsbergFTW thinks of one column containing the whole lines?

If col1 contains name1,name2, etc and col2 containes the value 3,4,5 etc and col3 contains either 'x' or 'o', then it could be:

Select t1.* from table t1 where col3='o'
union
Select t1.* from table t1 where not exists (select 1 from table t2 where t1.col1=t2.col1 and t2.col3='o')

Open in new window


It smells like you need something more thoug, as your final result also has distinct values of col1 you might want to group by col1 and pick one record per group. While my solution should work (untested), it would fail, if you had more records for eg name2 with x but another int value, eg name2,2,'x' additionally to name2,3,'x' would also come into the final result.

You need to be more specific in what you want, then.

Bye, Olaf.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question