3

I have created this sql select query:

SELECT subscription_new_projects.banners, subscription_new_projects.banner_link
FROM subscription_new_projects
WHERE be_famous_id =32
AND now( ) < end_date
ORDER BY subscription_new_projects_id DESC

and getting this sql result:

enter image description here

Now I want to set banners field empty, If banner_link is not empty.

I want this result:

enter image description here

My SQL Fiddle: Example

Any Idea how to do this?

Thanks.

2 Answers 2

2

You can use case-when

SELECT 
case 
when 
  subscription_new_projects.banner_link <> '' then '' 
  else subscription_new_projects.banners 
end as banners,  
subscription_new_projects.banner_link
FROM subscription_new_projects
WHERE be_famous_id =32
AND now( ) < end_date
ORDER BY subscription_new_projects_id DESC
Sign up to request clarification or add additional context in comments.

1 Comment

Working perfect for me. Thanks :)
0

Use CASEstatement.

Query

SELECT 
CASE WHEN subscription_new_projects.banner_link != ''
THEN NULL 
ELSE subscription_new_projects.banners
END AS banners,
subscription_new_projects.banner_link
FROM subscription_new_projects
WHERE be_famous_id =32
AND now( ) < end_date
ORDER BY subscription_new_projects_id DESC;

Fiddle demo

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.