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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:32:57+00:00 2026-05-18T21:32:57+00:00

I’ve worked with mysql for some time but have never had to do anything

  • 0

I’ve worked with mysql for some time but have never had to do anything anywhere near complicated. I’m working on a new project and need a little push in the right direction. Lets say I want to have a table that stores cats. Lets say I want to store the cats name, and food that the cat likes. Then lets say I want to query all cats that like fish, milk, and mice. I don’t want to have the ‘cats’ table have rows for ‘fish’ ‘milk’ ‘mice’ that can be yes or no or 1 or 0. I think want I’m looking for is having a separate ‘foods’ table and then use the join statement. But I have no clue where to start looking or what to search for. Another way to think about this would be if you had a blog, and wanted posts to have categories. How would I store which posts are in which categories, and how would I query for posts by category?

I realize this is probably a very basic question, and would be happy with even a link to a tutorial explaining the structure / commands needed to pull this off! Thanks a lot!

  • 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-18T21:32:58+00:00Added an answer on May 18, 2026 at 9:32 pm

    Table: cats
    id
    name

    Table: foods id name

    Table: cat_food cid (Cat ID) fid (Food ID)

    Query: Select cats that like fish
    SELECT
    name
    FROM
    cats c
    INNER JOIN
    cat_food cf
    ON
    cf.fid = 2 -- Assuming food ID#2 is 'fish'
    Query: Select cats that like fish, milk, or mice
    SELECT
    c.name
    FROM
    cats c
    INNER JOIN
    cat_food cf
    ON
    cf.fid IN (1, 2, 3)
    GROUP BY
    c.name

    SCHEMA
    CREATE TABLE IF NOT EXISTS cats (
    id int(10) unsigned NOT NULL AUTO_INCREMENT,
    name varchar(255) COLLATE utf8_unicode_ci NOT NULL,
    PRIMARY KEY (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;

    INSERT INTO cats (id, name) VALUES
    (1, 'Sassy'),
    (2, 'Tiger');

    CREATE TABLE IF NOT EXISTS cat_food (
    cid int(10) unsigned NOT NULL COMMENT 'Cat ID',
    fid int(10) unsigned NOT NULL COMMENT 'Food ID',
    UNIQUE KEY cid_fid (cid,fid),
    KEY fid (fid)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

    INSERT INTO cat_food (cid, fid) VALUES
    (1, 1),
    (2, 2),
    (1, 3);

    CREATE TABLE IF NOT EXISTS foods (
    id int(10) unsigned NOT NULL AUTO_INCREMENT,
    name varchar(255) COLLATE utf8_unicode_ci NOT NULL,
    PRIMARY KEY (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;

    INSERT INTO foods (id, name) VALUES
    (1, 'Fish'),
    (2, 'Milk'),
    (3, 'Mice');

    ALTER TABLE cat_food
    ADD CONSTRAINT cat_food_ibfk_2 FOREIGN KEY (fid) REFERENCES foods (id) ON DELETE CASCADE,
    ADD CONSTRAINT cat_food_ibfk_1 FOREIGN KEY (cid) REFERENCES cats (id) ON DELETE CASCADE;

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I want to count how many characters a certain string has in PHP, but
I need to clean up various Word 'smart' characters in user input, including but
I've got a string that has curly quotes in it. I'd like to replace
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.