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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:13:56+00:00 2026-05-26T14:13:56+00:00

Background I’ve got two tables with different types of feedback items in MySQL. I’ve

  • 0

Background

I’ve got two tables with different types of feedback items in MySQL. I’ve built a query to combine these tables by FULL OUTER JOIN (which is actually written as two joins and an union in MySQL) and to count some average grades. This query seems to work perfectly:

  (SELECT name, AVG(l.overallQuality) AS avgLingQual,
    AVG(s.overallSatisfaction) AS avgSvcQual
  FROM feedback_linguistic AS l
  LEFT JOIN feedback_service AS s USING(name)
  GROUP BY name)
UNION ALL
  (SELECT name, AVG(l.overallQuality) AS avgLingQual, 
    AVG(s.overallSatisfaction) AS avgSvcQual
  FROM feedback_linguistic AS l
  RIGHT JOIN feedback_service AS s USING(name)
  WHERE l.id IS NULL
  GROUP BY name)
ORDER BY name;

(This is somewhat simplified for readability but it doesn’t make a difference here)

Problem

Next I tried adding filtering by date (i.e. only feedback items created after a certain date are taken in account). With my SQL skills and the research I did, I was able to come up with this:

  (SELECT name, AVG(l.overallQuality) AS avgLingQual,
    AVG(s.overallSatisfaction) AS avgSvcQual
  FROM feedback_linguistic AS l
  LEFT JOIN feedback_service AS s USING(name)
  WHERE (s.createdTime >= '" & date & "' OR s.createdTime IS NULL)
    AND (l.createdTime >= '" & date & "' OR l.createdTime IS NULL)
  GROUP BY name)
UNION ALL
  (SELECT name, AVG(l.overallQuality) AS avgLingQual, 
    AVG(s.overallSatisfaction) AS avgSvcQual
  FROM feedback_linguistic AS l
  RIGHT JOIN feedback_service AS s USING(name)
  WHERE l.id IS NULL
    AND (s.createdTime >= '" & date & "' OR s.createdTime IS NULL)
  GROUP BY name)
ORDER BY name;

This almost works: the results I get look about right. However, a couple of feedback items are missing. For example, setting the date one month ago, I counted feedback for 21 different people in the database, but this query only returns 19 people. The worst thing is that I can’t seem to find any similarities between the missing items.

Am I doing something wrong in this query? I think that the WHERE clause does the date filtering after the JOIN and ideally I would probably be doing it before. Then again, I don’t know if this causes my problem and I also have no idea how to write this query differently.

  • 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-26T14:13:56+00:00Added an answer on May 26, 2026 at 2:13 pm

    A full outer join is a combination of 3 joins:

    1- inner join between A and B
    2- left exclusion join between A and B
    3- right exclusion join between A and B

    Note that the combination of an inner and a left exclusion join is a left outer join, so you normally rewrite the query as a left outer join + right exclusion join.
    However for debugging purposes it can be useful to union all 3 joins and to add some marker as to which join does what:

      /*inner join*/
      (SELECT
         'inner' as join_type 
         , COALESCE(s.name, l.name) as listname
         , AVG(l.overallQuality) AS avgLingQual
         , AVG(s.overallSatisfaction) AS avgSvcQual 
      FROM feedback_linguistic l 
      INNER JOIN feedback_service s ON (l.name = s.name) 
      WHERE (s.createdTime >= '" & date & "' OR s.createdTime IS NULL) 
        AND (l.createdTime >= '" & date & "' OR l.createdTime IS NULL) 
      GROUP BY l.name) 
    UNION ALL
      (SELECT
         'left exclusion' as join_type 
         , COALESCE(s.name, l.name) as listname
         , AVG(l.overallQuality) AS avgLingQual
         , AVG(s.overallSatisfaction) AS avgSvcQual 
      FROM feedback_linguistic l 
      LEFT JOIN feedback_service s ON (l.name = s.name) 
      WHERE s.id IS NULL
        /*AND (s.createdTime >= '" & date & "' OR s.createdTime IS NULL) */
        AND (l.createdTime >= '" & date & "' OR l.createdTime IS NULL) 
      GROUP BY l.name) 
    UNION ALL
      (SELECT 
         'right exclusion' as join_type
         , COALESCE(s.name, l.name) as listname
         , AVG(l.overallQuality) AS avgLingQual 
         , AVG(s.overallSatisfaction) AS avgSvcQual 
      FROM feedback_linguistic l 
      RIGHT JOIN feedback_service s ON (s.name = l.name) 
      WHERE l.id IS NULL
        AND (s.createdTime >= '" & date & "' OR s.createdTime IS NULL) 
        /*AND (l.createdTime >= '" & date & "' OR l.createdTime IS NULL) */
      GROUP BY s.name) 
    ORDER BY listname; 
    

    I think that the WHERE clause does the date filtering after the JOIN and ideally I would probably be doing it before.

    If you want to do the filtering before, then put it in the join clause.

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

Sidebar

Related Questions

Background: Some time ago, I built a system for recording and categorizing application crashes
Background: I have a performance-critical query I'd like to run and I don't care
Background I've got an NSOutlineView that shows TrainingGroup entities. Each TrainingGroup represents a folder
Background I've got the following tree of objects: Name Project Users nil John nil
Background: I have a little video playing app with a UI inspired by the
Background: At my company we are developing a bunch applications that are using the
Background: I need to reserve an amount of memory below 0xA0000 prior to my
Background I am writing and using a very simple CGI-based (Perl) content management tool
Background I have a massive db for a SharePoint site collection. It is 130GB
Background I am trying to create a copy of a business object I have

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.