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 8139295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:46:47+00:00 2026-06-06T11:46:47+00:00

I have a MySQL table with a structure like the following: I’m looking for

  • 0

I have a MySQL table with a structure like the following:

MySQL fields

I’m looking for a select statement which will concatenate the last four fields as follows:

ID    Source
1     Search engine
2     Email
3     Coupon mailout
4     Relative of owner

I can think of a way to do this by using subqueries to choose the relevant fields to concatenate based on Type, nested subqueries to select values that are not NULL or ‘Other’, followed by JOINs, CONCAT()s and a UNION, but that seems a very complicated approach to the problem.

Am I overthinking this? Is there a simpler way?

  • 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-06T11:46:49+00:00Added an answer on June 6, 2026 at 11:46 am

    If you can’t fix your data, you can simply use IF() function. In my example, I’m using simple column names to make it a bit clearer:

    mysql> SELECT IF(c1 IS NOT NULL AND c1 != 'Other', c1,
            IF(c2 IS NOT NULL AND c2 != 'Other', c2,
            IF(c3 IS NOT NULL AND c3 != 'Other', c3, c4))) FROM t1;
    

    The above was tested.

    You could make a Stored Function out of it if you need to use it often.

    But, if you can, fix the table structure?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an table structure like this mysql> SELECT id, name, parent_id FROM categories;
In MySQL, is it bad to have a table structure like the following... Table
I have a mysql table structure like that: id int primary key name varchar
I have a mysql database with a table structure like below : Table Name
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have the following MySQL table structure: num field company phone website 1 Gas
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
I have a mysql table of the following structure. So the above table stores
I have a MySQL database with the following table structure: TransactionType : Transaction_Amount, Transaction_ID,
I have mysql table with following fields id (which auto increments) title,name,age,institution,iod the fields

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.