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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:54:42+00:00 2026-06-14T16:54:42+00:00

i already submit my problem but without example it was not clear enough so

  • 0

i already submit my problem but without example it was not clear enough so here is the tables :

Users
id_user / key_user
1       / 123FDADA21312QD
2       / 994GFCS4595433D

Companies
id_company / key_company
1          / 3123123123
2          / 5435345454

Products
id_product / id_company_product / code_product
1          /     1              / iphone
2          /     1              / iBook
3          /     1              / macbook

Tyds
id_tyd  / user_tyd / product_tyd
1       /   1      /   1        -- mean that the id_user = 1 made a line for the iphone 
                                   sold by the company 1
2       /   1      /   2        -- same : user 1 for the ibook of company 1

Here is my request :

SELECT 
products.id_product,
users.id_user,
COALESCE(id_tyd, 'NONE') AS id_tyd 
FROM tyds
INNER JOIN users
ON tyds.user_tyd = users.id_user
INNER JOIN products
ON tyds.product_tyd = products.id_product
INNER JOIN companies
ON products.id_company_product = companies.id_company 
WHERE users.key_user = '123FDADA21312QD'
AND companies.module_key_company = '3123123123'
AND products.cancelled_product >= 0
AND products.code_product = 'iphone'

That will return

products.id_product = 1
users.id_user = 1 
tyds.id_tyd = 1

Perfect. But what i’d like to do is getting the users.id_user EVEN IF there is no records for this user in tyds. Like :

SELECT 
products.id_product,
users.id_user,
COALESCE(id_tyd, 'NONE') AS id_tyd 
FROM tyds
INNER JOIN users
ON tyds.user_tyd = users.id_user
INNER JOIN products
ON tyds.product_tyd = products.id_product
INNER JOIN companies
ON products.id_company_product = companies.id_company 
WHERE users.key_user = '123FDADA21312QD'
AND companies.module_key_company = '3123123123'
AND products.cancelled_product >= 0
AND products.code_product = 'macbook'

I’d like to get :

  • products.id_product = 3
  • users.id_user = 1
  • tyds.id_tyd = NONE

Because at this step, i’m sure that the product i ask exists and the user_key exist. But i’m not sure that there is matching records in tyds and that is what i want to test.

Of course, all the tables are simplify and i’ll need more datas but i think this will make my point.

My first move was to put the WHERE condition in the JOIN match but, don’t know why, if i put the products.code_product in the products jointure, it give me tyds records even for different id_product…

Thanks a lot for your help !

  • 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-14T16:54:43+00:00Added an answer on June 14, 2026 at 4:54 pm

    if that’s the case, change the join from INNER JOIN to LEFT JOIN. INNER JOIN, basically returns rows that are present (atleast one match) on all tables being joined, while LEFT JOIN returns rows on the lefthand side even without matching records on the other tables.

    Query,

    SELECT c.*, d.id_tyd
    FROM
        (
          SELECT  a.id_user, b.id_product
          FROM    users a CROSS JOIN products b
        ) c
        LEFT JOIN tyds d
          ON d.user_tyd = c.id_user AND
             d.product_tyd = c.id_product
        LEFT JOIN products e
          ON e.id_product = c.id_product
        LEFT JOIN companies f
          ON e.id_company_product = f.id_company
        LEFT JOIN users g
          ON c.id_user = g.id_user
    WHERE e.code_product = 'macbook' AND
          f.key_company = '3123123123' AND
          g.key_user = '123FDADA21312QD'
    
    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: I'm not considering this is Drupal problem so I post it here on
been working on this way too long...but can't seem to identify the problem. Already
I've just started learning jQuery and already love it, but my skills aren't enough
I am developing a web application, but the submit button does not appear as
Simple enough, it would seem, but it turns out not to be - mainly
Already finished implementing the player. I want to implement the progress bar. But I
Already found this page with some helpful hints. Problem is I need to debug
I already know about Ghostscript front end viewers; but I was wondering how gs
I already asked this question but at that time I tought that the refresh
I use ckeditor in admin panel but in user submit form use simple textbox

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.