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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:50:44+00:00 2026-06-10T13:50:44+00:00

Assuming you have a multiple boolean fields within a common category, which database storage

  • 0

Assuming you have a multiple boolean fields within a common category, which database storage method is more efficient for both speed and processing (for both MySQL and PHP)?

For example, if choosing a car you may have a category “options” with the following selections:
(GPS,Tow package,Radar,Powersteering). All options are boolean fields, which must be answered, and must be TRUE or FALSE.

Is it better to set up a table with each field:

CREATE TABLE IF NOT EXISTS `manycars` (
  `vin` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `hasGps` tinyint(1) NOT NULL COMMENT '1= TRUE, 0=FALSE',
  `hasTow` tinyint(1) NOT NULL COMMENT '1= TRUE, 0=FALSE',
  `hasRadar` tinyint(1) NOT NULL COMMENT '1= TRUE, 0=FALSE',
  `hasPsteer` tinyint(1) NOT NULL COMMENT '1= TRUE, 0=FALSE',
  PRIMARY KEY (`vin`),
) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

or choose a single field named “options” with a bit style data storage, such as:

CREATE TABLE IF NOT EXISTS `singlecars` (
  `vin` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `options` int(3) unsigned NOT NULL COMMENT '1= GPS, 2=Tow, 4=radar, 8=psteer',
  PRIMARY KEY (`vin`),
) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

In order to determine the values for each boolean, I would then query such as SELECT options, vin FROM singlecars and extract:

$q=SELECT options, vin FROM singlecars
$r=mysqli_query($dbconnect, $q);
while($record = mysqli_fetch_array($r, MYSQLI_ASSOC)){
  $option=decbin($record['options']; // returns binary
  $gps=substr($option,3,1);
  $tow=substr($option,2,1);
  $radar=substr($option,1,1);
  $psteer=substr($option,0,1);
  echo "GPS=$gps, Tow package=$tow, Radar=$radar, Power Steering=$psteer <br />";
}

My thoughts are that the first table “manycars” has better semantics, and is quick to query and minimal php code to write a query. However, the second table “singlecars” uses less SQL structure, and in the case where all options are boolean, are likely to be needed everytime.

This is a theoretical example, but I am interested in the pro/con of each method.

  • 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-10T13:50:45+00:00Added an answer on June 10, 2026 at 1:50 pm

    I would go for the variant with separate fields for each option.

    • It’s faster: you don’t need to use substr in your while loop (this
      is a place where you can have a slowdown while dealing with
      large volume of data).
    • It’s flexible: for instance, you need to select all cars with
      radar. SELECT ... WHERE hasRadar = 1. That’s it.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have the following two JQuery functions - The first, which works: $(#myLink_931).click(function
In java world (more precisely if you have no multiple inheritance/mixins) the rule of
I have a database of wireless access points and multiple readings (1-n) of signal
so I was wondering, assuming you have a multiple selector as below: $('.BOO li',
Assuming I have a numerical string: var foo = 0; Assume I want to
Assuming I have a ASP.NET MVC 3 application that runs in a web farm
assuming I have the following array: views = [ { :user_id => 1, :viewed_at
Assuming i have a post model with created_at, title, and id. How can i
Assuming I have a column called A and I want to check if A
Assuming you have only the URL to a file (hosted on the same server

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.