/    Sign up×
Community /Pin to ProfileBookmark

MySWL Table join inconsistencies

I have an SQL statement which Joins 3 tables and then produces some results.

https://www.db-fiddle.com/f/v1zExsp4ZVnnq1hQYJKcXY/0

PROBLEM: DB Fiddle actually gives me the correct results BUT My Database: Version: 10.0.38-MariaDB – Gives different results.

Both DBs show all 48 rows when the `sale_category=’Non-Productive’` filter is removed.

BUT – Only DB Fiddle filters correctly to 15 rows of data when the `sale_category=’Non-Productive’` filter is present.

My MariaDB filters incorrectly resulting in 32 rows of data. (see attached)

[upl-image-preview url=https://www.webdeveloper.com/forum/assets/files/2019-02-13/1550037403-172956-image.png]

My database is displaying results which should be filtered (e.g. any row with sale_type=CUSTOMER) BUT is showing them as ‘Non-Productive’ and I have no idea why (especially after testing in DB Fiddle and seeing desired results)

  • 1. Why is it so?

  • 2. Is there a more efficient SQL query?

  • to post a comment

    3 Comments(s)

    Copy linkTweet thisAlerts:
    @NogDogFeb 13.2019 — I don't know why they would have different results unless the actual data is different, but this looks a bit iffy:
    <i>
    </i>INNER JOIN ReportHeader rh1 ON rd.report_id=rh1.id
    INNER JOIN ReportHeader rh2 ON st.customer_id=rh2.customer_id

    Do you get anything better if you consolidate that to a single join?
    <i>
    </i>INNER JOIN ReportHeader rh1 ON rd.report_id=rh1.id AND st.customer_id=rh1.customer_id
    Copy linkTweet thisAlerts:
    @php-bgraderauthorFeb 13.2019 — Ha! Yes @NogDog - I get the exact results I am expecting...

    I only added those 2 lines after the fact (when I started trying to narrow the resultset) - I googled how to use 1 table with 2 joins and all i got was what I had - I thought there had to be a way to do it better - and here it is.

    Perfect. Thanks!
    Copy linkTweet thisAlerts:
    @rootFeb 15.2019 — Also remember that there can be minor but significant difference in how a database interprets that command, running on one database does not mean the same result off the other database.

    I have been in that situation, about two lifetimes ago, scratching my head for ages until I googled why blah blah command in blah blah does not work...
    ×

    Success!

    Help @php-bgrader spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...