0

Consider the below table T1

FLOOR...ANIMAL...COLOUR

1...Cat...Black

1...Dog...Black

1...Cat...White

2...Dog...White

2...Dog...Brown

3...Cow...Brown

3...Dog...White

3...Cat...Black

Now, I with query: Select * from T1 where animal='cat'; got this Table T2

Table T2

FLOOR...ANIMAL...COLOUR

1...Cat...Black

1...Cat...White

3...Cat...Black

The result I want is: All the elements present in Table T2 and only(FLOOR,ANIMAL) of Table T1. Something like the below Table T3:

Table T3

FLOOR...ANIMAL...COLOUR

1...Cat...Black

1...Cat...White

3...Cat...Black

1...Dog

2...Dog

2...Dog

3...Cow

3...Dog

How this Table T3 can be acheived? Any suggestions? Thanks in advance.

1
  • Please show the entire expected output and clearly explain the logic behind it. Commented Mar 11, 2018 at 6:49

2 Answers 2

1

You could try taking the UNION of two TABLES wherein the second TABLE should have its third column as empty string:

select * from T1 where animal = 'cat' UNION select floor, animal, " " as color from T1 where animal <> 'cat';

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot.It really helped.
0

You can try with case

like this :

case when ANIMAL = "cat" then COLOUR else '' end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.