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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:38:00+00:00 2026-05-17T00:38:00+00:00

I have a single DB table (MySQL) which I am running a simple SELECT

  • 0

I have a single DB table (MySQL) which I am running a simple SELECT on. In this table I have 3 fields which contain 3 possible values each. In each case the values are identical (‘none’,’online’,’physical’). I want to return in my result a true or false value for an alias if any one of these fields are not set to ‘none’.

I can easily evaluate this in PHP after I’ve returned my result set but in order to sort my results easily I would rather generate the true/false in the SELECT if possible. So at present a result row might look like this:

id: 1 
trial_type_1: none
trial_type_2: online
trial_type_3: none

In this case I want the query to return:

id: 1
trial: True

If all the trial_type fields were set to none then it would return a trial value of False. Any ideas greatly appreciated since I really have no idea where to start or even what to search for online! 🙂

  • 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-05-17T00:38:01+00:00Added an answer on May 17, 2026 at 12:38 am

    I’d use a case statement within this, it’s a very flexible method and can be very useful.

    select id, 
    (CASE WHEN trial_type_1 <> 'none' OR trial_type_2 <> 'none' 
               OR trial_type_3 <> 'none'
     THEN 'True' ELSE 'False' END) as trial
    FROM q3773072
    

    However you could equally well do it as a simple logical operation – which maybe closer to what you want, as follows:

    SELECT id, 
           (trial_type_1 <> 'none' OR  trial_type_2 <> 'none'  OR trial_type_3 <> 'none' )  as Trial  
    from q3773072
    

    The correct way of doing this is of course to store the multiple trial_types in a different table – when you start to number fields it is a clue that the database schema needs changing. You should also set-up another table that defines the trial types and their definition – i.e. whether or not they are a real trial.

    I’d probably adopt the latter approach as it is highly likely that you will be adding another trial type at some point in the future and it will be painful if you don’t do it right..

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

Sidebar

Related Questions

I have a single product table with multiple fields which contain user evaluations of
I have a MySQL table which contains a list of all possible products a
this is my problem: I have a table in my mysql database which contains
In MySQL+InnoDB, suppose I have a single table, and two threads which both do
I have a huge access mdb file which contains a single table with 20-30
I have a simple database named customer with a single table data.I want to
So I have this function that takes all the users from an MySql table
I have a MySQL table that looks like this: id (int primary) name (text)
I have a database table (MySQL 5) which stores file hashes and filenames. I
We are using mysql. We have a huge table which contains 1 billion rows.

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.