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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:29:35+00:00 2026-05-22T01:29:35+00:00

I have a MySQL table as follow: id, user, culprit, reason, status, ts_register, ts_update

  • 0

I have a MySQL table as follow:

id, user, culprit, reason, status, ts_register, ts_update

I was thinking of using the reason as an int field and store just the id of the reason that could be selected by the user and the reason itself could be increased by the admin.

What I meant by increased is that the admin could register new reason, for example currently we have:

Flood, Racism, Hacks, Other

But the admin could add a new reason for instance:

Refund

Now my problem is that I would like to allow my users to select multiple reasons, for example:

The report 01 have the reasons Flood and Hack.

How should I store the reason field so that I could select multiple reasons while maintaining a good table format?

Should I just go ahead and store it as a string and cast it as an INT when I am searching thru it or there are better forms to store it?

UPDATE Based on Jonathan’s reply:

SELECT mt.*, group_concat(r.reason separator ', ') AS reason
  FROM MainTable AS mt
  JOIN MainReason AS mr ON mt.id = mr.maintable_ID
  JOIN Reasons AS r ON mr.reason = r.reason_id
  GROUP BY mt.id
  • 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-22T01:29:36+00:00Added an answer on May 22, 2026 at 1:29 am

    The normalized solution is to have a second table containing one row for each reason:

    CREATE TABLE MainReasons
    (
        MainTable_ID INTEGER NOT NULL REFERENCES MainTable(ID),
        Reason       INTEGER NOT NULL REFERENCES Reasons(ID),
        PRIMARY KEY(MainTable_ID, Reason)
    );
    

    (Assuming your main table is called MainTable and you have a table defining valid reason codes called Reasons.)


    From a comment:

    [W]ould you be [so] kind [as] to show me an example of selecting something to retrieve a report’s reason? I mean if I simple select it SELECT * FROM MainTABLE I would never get any reasons since MainTable doesnt know it right? Because it is only linked to the MainReasons and Reasons table so I would need to do something like SELECT * FROM MainTable LEFT JOIN MainReasons USING (MainTable_ID) or something alike but how would I go about getting all the reasons if multiples?

    SELECT mt.*, r.reason
      FROM MainTable AS mt
      JOIN MainReason AS mr ON mt.id = mr.maintable_ID
      JOIN Reasons AS r ON mr.reason = r.reason_id
    

    This will return one row per reason – so it would return multiple rows for a single report (recorded in what I called MainTable). I omitted the reason ID number from the results – you can include it if you wish.

    You can add criteria to the query, adding terms to a WHERE clause. If you want to see the reports where a specific reason is specified:

    SELECT mt.*
      FROM MainTable AS mt
      JOIN MainReason AS mr ON mt.id = mr.maintable_ID
      JOIN Reasons AS r ON mr.reason = r.reason_id
     WHERE r.reason = 'Flood'
    

    (You don’t need the reason in the results – you know what it is.)


    If you want to see the reports where ‘Floods’ and ‘Hacks’ were the reasons given, then you can write:

    SELECT mt.*
      FROM MainTable AS mt
      JOIN (SELECT f.MainTable_ID
              FROM (SELECT MainTable_ID
                      FROM MainReason AS mr1
                      JOIN Reasons    AS r1  ON mr1.reason = r1.reason_ID
                     WHERE r1.reason = 'Floods'
                   ) AS f ON f.MainTable_ID = mt.MainTable_ID
      JOIN (SELECT f.MainTable_ID
              FROM (SELECT MainTable_ID
                      FROM MainReason AS mr2
                      JOIN Reasons    AS r2  ON mr2.reason = r2.reason_ID
                     WHERE r1.reason = 'Hacks'
                   ) AS h ON h.MainTable_ID = mt.MainTable_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have MYSQL tables as follows user TABLE {id INT} profile TABLE {user_id INT,
I have a MySQL table called accounts . Within this table is a field
I have the follow two mysql tables: mysql> desc subscriptions; +------------+--------------+------+-----+---------+----------------+ | Field |
I have a textarea in html that gets saved to a mysql table using
In Drupal, I have a table node that gets generated from mysql user data.
Suppose I have a table as follows in MySQL: create table user(name varchar(20), join_time
Here's a mysql table : friends : followed INT, <-- The user's id (
I have a mysql table as follows. CREATE TABLE `events` ( `event_id` int(11) NOT
I have two MySQL tables structed as follows; advert +-------------------+--------------+ | Field | Type
I'm using PHP/MySql. If I have two tables (hypothetically) as follows: id name and

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.