Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to lots of booleans in MySQL?

Tags:

php

mysql

let's say I have a checkbox search form like this:

Check all that interests you:

  • bowling
  • billiard
  • sweets

Can I request this data from a database instead of having to resort adding tons of booleans to a database such as this?

(VenueId, IfBowling, IfBilliard, IfSweets)

And maybe just have one column that would contain all of those options that the venue itself has?

like image 633
pufAmuf Avatar asked Aug 27 '11 14:08

pufAmuf


1 Answers

Alternative .. sure .. easy :

User table, Interests table, UserInterests table.

UserInterests is used to store many-to-many relation between Users and Interests, and contains values which are FOREGN KEYs from said tables.

P.S. You really should read SQL Antipatterns book. You would learn a lot from it.

like image 184
tereško Avatar answered Oct 01 '22 23:10

tereško