-2

I have a table T1 with the following columns and rows/row data:

               table T1
child_id | childOne    |  ChildHired | ChildProgress  
1          Yes            No            Good  
2          No             No            Poor
3          Yes            Yes           Fair

I need to use a select case condition so that only the rows which satisfy my condition appear in the result and the rows which don't fulfill the condition should not show up in my result.

When I execute:

select (case when childOne='yes' then true else false end) from T1;

The query works but the [childOne='No'] rows appear too. How can make the rows that don't satisfy a certain condition not show up in my result set?

Zafar Malik
  • 6,734
  • 2
  • 19
  • 30
Nsengiyunva
  • 11
  • 1
  • 9
  • you can use where condition.. – Zafar Malik Aug 17 '15 at 08:31
  • oh...lemme look into that – Nsengiyunva Aug 17 '15 at 08:35
  • 1
    So you are learning SQL and haven's read about the WHERE clause yet? It should be in one of the very first pages, whereas CASE WHEN should be treated much later. Maybe you should get yourself a better tutorial / book if yours is teaching you more advanced stuff before treating the basics. – Thorsten Kettner Aug 17 '15 at 08:40
  • f.y.i Mr.Thorsten --> i know all about the where clause. in this question, i need to know how i can use the select case where kind of clause...that i havent learnt so well! #ThanksAnyway – Nsengiyunva Aug 17 '15 at 08:43

1 Answers1

0

use below one-

select * 
from T1 
where childOne='yes';

Example of Case:

select case when childOne='yes' then childProgress 
when childOne='No' then childHired else childOne end 
from T1 ;
Zafar Malik
  • 6,734
  • 2
  • 19
  • 30
  • i want you to use a select case -- a conditional select and a where clause to get me the result! i know how a where clause works please! – Nsengiyunva Aug 17 '15 at 08:54
  • basically case is useful when you want to show differnt columns data based on certain conditions, you can check example in my update... – Zafar Malik Aug 17 '15 at 08:57
  • That table T1 is just a snippet of a much larger table , now i have been asked to choose rows based on what their values is! in other words, i have to use an if or case statement which i know and understand. what am asking is: how can i select case the rows but leave out the ones that dont satisfy my conditon??? get it now?? #Thanks – Nsengiyunva Aug 17 '15 at 08:57
  • i know the basics of a case condition. here is what i need: if i execute query: select case when childOne='ýes' then 'yes' else [nothing]; end from t1; – Nsengiyunva Aug 17 '15 at 09:10
  • i am checking for a yes or No answer value in childOne column! so if the childOne is not equal to 'yes' then the row should not appear! – Nsengiyunva Aug 17 '15 at 09:11
  • you have to understand feature of case as case provide you rows based on condition and rest will go in else condition but you can't eliminate rows by this...to eliminate you have to use where clause.... – Zafar Malik Aug 17 '15 at 09:12
  • Now thats the kind of answer i was looking for -- now amma look for select case where example maybe! not learning the basics of a where clause or a how a selectr case condition works because i already know how it works! # Thank You! – Nsengiyunva Aug 17 '15 at 09:23