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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:31:10+00:00 2026-06-01T02:31:10+00:00

I have 2 tables in my mysql database: CREATE TABLE IF NOT EXISTS `RECIPES`

  • 0

I have 2 tables in my mysql database:

CREATE TABLE IF NOT EXISTS `RECIPES` (
  `recipes_id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(50) COLLATE utf8_bin NOT NULL,
  `text` varchar(2000) COLLATE utf8_bin NOT NULL,
  `count_persons` int(11) NOT NULL,
  `duration` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `date` datetime NOT NULL,
  `accepted` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`recipes_id`),
  KEY `recipes_user_fk` (`user_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=88 ;

CREATE TABLE IF NOT EXISTS `RECIPES_POS` (
  `recipes_pos_id` int(11) NOT NULL AUTO_INCREMENT,
  `recipes_id` int(11) NOT NULL,
  `ingredients_id` int(11) NOT NULL,
  `ingredients_value` int(11) NOT NULL,
  PRIMARY KEY (`recipes_pos_id`),
  KEY `recipe_pos_rec_id` (`recipes_id`),
  KEY `recipes_pos_ingredient_fk` (`ingredients_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=58 ;

In the Recipe_Pos Table are many entries. This table shows what ingredients are used in the Recipe.

Now i want to find the recipe which contains incredients like powder and sugar:

SELECT r.recipes_id FROM RECIPES r, RECIPES_POS rp WHERE r.recipes_id = rp.recipes_id AND rp.ingredients_id =6 AND rp.ingredients_id =4

this statment is wrong because a entry in Recipe_Pos can’T contains both incredients.

Whats the right query? It should works with only 1 incredient and more

  • 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-01T02:31:11+00:00Added an answer on June 1, 2026 at 2:31 am
    select r.recipes_id
    from RECIPES r
    inner join RECIPES_POS rp on r.recipes_id = rp.recipes_id
    where rp.ingredients_id in (4, 6)
    group by r.recipes_id
    having count(distinct rp.ingredients_id) = 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have in my MySQL database these two tables: CREATE TABLE IF NOT EXISTS
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a mysql table like this (sql): CREATE TABLE IF NOT EXISTS silver_and_pgm
Database is MySQL with MyISAM engine. Table definition: CREATE TABLE IF NOT EXISTS matches
I have a mysql table with items in relation to their order. CREATE DATABASE
I have to create a database with two tables in MySQL, but the script
I have a mysql database which have set of tables One table have a
I inherited MYSQL database that has lots of tables with data like CREATE TABLE
I have created a MySQL database using MySQL Workbench. It has about 20 tables.
I have a MySQL database with 60 tables. Most of the tables have primary

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.