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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:35:31+00:00 2026-05-26T15:35:31+00:00

I am trying to put together a mysql query, that links 3 tables together.

  • 0

I am trying to put together a mysql query, that links 3 tables together. In essence, the tables are as follows:

  1. products – Contains product information and basic pricing.
  2. product_depts – Linking table that links products to different departments.
  3. promotions – Another linking table, links promotion periods and prices based on product id.

This is the query:

SELECT p.id, `desc` , price1, price2, cost1, taxable, quantity, deptId, sale
FROM products p
INNER JOIN product_depts ON p.id = prodId
INNER JOIN promotions s ON p.id = s.id
WHERE MATCH (
`desc`
)
AGAINST (
'CLOVER'
IN BOOLEAN
MODE
)
ORDER BY `desc`
LIMIT 0 , 30

If the following line is removed:

INNER JOIN promotions s ON p.id = s.id

And sale taken out of the select clause,

What happens, is ALL the products with a description containing “CLOVER”, in the products table, are returned.

With the addition of the removed query parts, only the items that are on promotion (have a matching id in the promotions table), are returned. And any additional products containing “CLOVER” in the products table, that are not “on promotion” are left out.

As I have very limited knowledge with mysql, I thought maybe someone that does have a great deal of knowledge on the matter to share… Would like to provide some input with this.

As i understand it though, this would be essentially the same thing as calling deptId from the product_depts table, which works perfectly. So it is confusing me.

What am i doing wrong that only the items that are “on promotion” are displayed and the additional results are left out?

Thank you!

  • 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-26T15:35:32+00:00Added an answer on May 26, 2026 at 3:35 pm

    INNER joins basically say “retrieve all records where there’s a matching record in BOTH tables”.

    If I’m reading your question correctly, it sounds like what you’d want is a LEFT or RIGHT join, which translates to “retrieve all records from one table, and (if any) matching records from the other table.

    Sounds like you want to get all products, whether they have a promotion or not, but if they do have a promotion, retrieve the promo info as well.

    That’d be

    SELECT ...
    FROM products
    INNER JOIN product_depts ON ...
    LEFT JOIN promotions ON ...
    

    So… all products MUST have a department, so do an inner join for that particular part of the query. The left join on promotions makes the ‘products’ table be the LEFT table, so all records from that table are fetched. The promotions table becomes the RIGHT table, and only provides data for the query results if there’s a matching record in the promotions table.

    So… given 2 products, 1 of which is on sale, you’d get

       product #1    department #1   promoinfo #1
       product #2    department #2   NULL
    

    for results. Since there’s no matching promo information for the #2 product, you get NULL for the promo data.

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

Sidebar

Related Questions

I'm trying to put together a MYSQL query that will count the number of
I am trying to put together a query that will display one specific record
Can anyone help me with a MySQL query I'm trying to put together. I
I trying to put together an Android app that will take a picture and
I'm trying to put together a simple RSS widget (for my wordpress blog) that
I'm trying to put together a form_tag that edits several Shift objects. I have
I put together a simple script that pulls the product name, category name and
So I am trying to put together a small lightweight framework for some basic
I'm trying to put together an app for fun that has a scenario where
I'm trying to put together some jQuery code that will add form elements (input

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.