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

  • Home
  • SEARCH
  • 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 7826697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:32:04+00:00 2026-06-02T09:32:04+00:00

All the 3 following tables have a date_v_end field which is a validity date.

  • 0

All the 3 following tables have a “date_v_end” field which is a validity date. As long as it’s NULL this means it’s the current “good” value.

For example, to select the current values of the table categorie we can simply do SELECT * FROM categorie WHERE date_v_end IS NULL.

I have 3 tables:

  • a table categorie (category in English)
  • a table “one to many” categorie_produit (category <=> product in English)
  • a table produit (product in English)

I’d like to make a query of all the current categories, and their one to many produit, and I still need one result even if the category has no product (= no produit_categorie row).

Before having the “date_v_end” field I did it this way:

SELECT
  c.id AS c_id,
  c.titre AS c_titre,
  c.description AS c_description,
  cp.id_categorie AS cp_id_categorie,
  cp.id_produit AS cp_id_produit,
  p.id AS p_id,
  p.titre AS p_titre,
  p.description AS p_description
FROM categorie_produit cp
LEFT OUTER JOIN categorie c
ON c.id=cp.id_categorie
LEFT OUTER JOIN produit p
ON p.id=cp.id_produit
ORDER BY c_id,p_id;

It worked like a charm. Now I’m trying to modify the query with the new “date_v_end” field. I’ve added the three clauses WHERE c.date_v_fin IS NULL AND cp.date_v_fin IS NULL AND p.date_v_fin IS NULL. There you go:

SELECT
  c.id AS c_id,
  c.titre AS c_titre,
  c.description AS c_description,
  cp.id_categorie AS cp_id_categorie,
  cp.id_produit AS cp_id_produit,
  p.id AS p_id,
  p.titre AS p_titre,
  p.description AS p_description
FROM categorie_produit cp
LEFT OUTER JOIN categorie c
ON (c.id=cp.id_categorie AND c.date_v_fin IS NULL)
LEFT OUTER JOIN produit p
ON (p.id=cp.id_produit AND p.date_v_fin IS NULL)
WHERE cp.date_v_fin IS NULL
ORDER BY c_id,p_id;

This works fine except in one circumstance: when there’s a categorie_produit and its “date_v_end” is not NULL: before adding this damn “date_v_end” field, I got one row with c_id, c_titre, and c_description filled and the other fields NULL (cp_id_categorie, cp_id_produit,p_id,p_titre,p_description). Now there’s no result.

I really don’t know how I can modify my query to make it work. Any idea?

  • 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-02T09:32:07+00:00Added an answer on June 2, 2026 at 9:32 am

    You need to move the IS NULL check into the JOINs.

    In your version you join, regardless of the date_v_fin field, and then filter the results.

    In the query below a record is only joined if the date_v_fin field IS NULL.

    SELECT
      c.id AS c_id,
      c.titre AS c_titre,
      c.description AS c_description,
      cp.id_categorie AS cp_id_categorie,
      cp.id_produit AS cp_id_produit,
      p.id AS p_id,
      p.titre AS p_titre,
      p.description AS p_description
    FROM
      categorie c
    LEFT OUTER JOIN
      categorie_produit cp
        ON  c.id=cp.id_categorie
        AND cp.date_v_fin IS NULL
    LEFT OUTER JOIN
      produit p
        ON  p.id=cp.id_produit
        AND p.date_v_fin IS NULL
    WHERE
      c.date_v_fin IS NULL
    ORDER BY
      c_id,
      p_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following tables: magazine_tags news_tags page_tags content_tags faq_tags They all have exactly
I have the following query (all tables are innoDB) INSERT INTO busy_machines(machine) SELECT machine
I have the following 3 rails classes, which are all stored in one table,
I have the following tables: --table sportactivity-- sport_activity_id, home_team_fk, away_team_fk, competition_id_fk, date, time (tuple
I have the following tables: CREATE TABLE `attendance_event_attendance` ( `id` int(11) NOT NULL AUTO_INCREMENT,
I have the following tables (this is abbreviated) tableAssignments id timestamp // updated when
I have the following two tables activity(activity_id, title, description, group_id) statistic(statistic_id, activity_id, date, user_id,
I have the following tables: CREATE TABLE `orders` ( `ID` varchar(5) NOT NULL, `IDUserProfile`
I have the following tables/columns: Parent: ParentID Child: ChildID ParentID SubChild: SubChildID ChildID Date
Problem Given the following two tables, I'd like to select all Ids for Posts

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.