Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7948393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:42:35+00:00 2026-06-04T01:42:35+00:00

I am creating a simple search query. I’d like to select a column that

  • 0

I am creating a “simple” search query. I’d like to select a column that should have the value 1 if a specified column LIKE(‘test’), it’s kind of hard to explain.

What i want to do is like this

SELECT *,(CASE mycol LIKE('%test%') as match THEN 1 END) FROM mytable

So if mycol matches the condition, then match=1, if else 0. How would i do that? Sorry if hard to understand.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:42:37+00:00Added an answer on June 4, 2026 at 1:42 am

    You are nearly there, but you have made four errors and used one bad practice:

    • Add ELSE 0 in your CASE expression.
    • CASE expressions need one or more WHEN expressions.
    • Put the alias in the correct place – after the end of the expression.
    • Don’t use the reserved word match as an alias.

    Also, don’t use SELECT *.

    Try this:

    SELECT
        col1,
        col2,
        ...,
        coln,
        CASE WHEN mycol LIKE '%test%' THEN 1 ELSE 0 END AS zipmatches
    FROM mytable
    

    However there’s no need for the CASE expression in MySQL because TRUE and 1 are equivalent:

    SELECT
        col1,
        col2,
        ...,
        coln,
        mycol LIKE '%test%' AS zipmatches
    FROM mytable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem that i'm creating a simple search application which have
Seems simple enough. I'm creating a search engine that returns results to the user
I am creating a simple Prism 2.1 demo that uses the 'directory search' approach
I am creating a simple search feature that queries a user input string for
In a binary search tree that takes a simple object.....when creating the getter and
Simple search engine issues.. I'm creating a simple search engine but i'm not able
I am creating simple app on Silverlight 4. In folder of View I have
I am creating a simple application with Django. I realized that I am doing
I am creating a simple comparison script and I have some questions for the
I am creating a simple ASP page that has a Repeater control. This repeater

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.