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

  • Home
  • SEARCH
  • 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 8900779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:10:53+00:00 2026-06-15T01:10:53+00:00

In my table I need to search specific columns in a specific row to

  • 0

In my table I need to search specific columns in a specific row to find which column contains the value I define.

For example in my table

ID | Col1 | Col2 | Col3 | Col4 | Col5 | Col6
--------------------------------------------
1  | A    | B    | C    | C    | B    | A
2  | C    | B    | A    | A    | C    | B
3  | B    | A    | C    | B    | A    | C

I need a query to search columns 4, 5 and 6 in Row 2 and tell me in which column value B occurs (Col6).

  • 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-15T01:10:55+00:00Added an answer on June 15, 2026 at 1:10 am

    Using a series of CASE conditions to match 'B' against each column will do the job. Each must supply the string literal name of the column as its THEN value. You cannot dynamically determine the column names – they must be hard-coded.

    SELECT
      CASE
        WHEN Col2 = 'B' THEN 'Col2' 
        WHEN Col4 = 'B' THEN 'Col4'
        WHEN Col6 = 'B' THEN 'Col6'
        ELSE 'Not found' 
      END AS which_column
    FROM 
      yourtable
    WHERE id = 2
    

    To return more than one, you can wrap the CASE statements in a CONCAT() that returns either the column name or an empty string. This means using several separate CASE statements though, instead of multiple conditions for the same case.

    SELECT
      CONCAT(
        CASE WHEN col2 = 'B' THEN 'Col2 ' ELSE '' END,
        CASE WHEN col4 = 'B' THEN 'Col4 ' ELSE '' END,
        CASE WHEN col6 = 'B' THEN 'Col6' ELSE '' END
      ) AS which_columns
    FROM yourtable
    WHERE id = 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have xpath page.search(//table[@class='campaign']//table) which returns two tables. I need to choose only first
I currently need to search a table of items to validate a list of
I need a table that stores key-value pairs, so I created one with a
I'm currently working on a query to search a specific table. The requirements say
I'm trying to find the sum of specific values within a table, using SQL.
I have a table that contains maybe 10k to 100k rows and I need
I'm trying to find a more performance way to search a log table. The
I need to implement a search in mysql table for a certain word to
I have one table, and I need to remove a specific text from a
I need to search rows entered on a specific date. However the datatype of

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.