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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:07:48+00:00 2026-06-08T02:07:48+00:00

This query displays the correct result but when doing an EXPLAIN, it lists it

  • 0

This query displays the correct result but when doing an EXPLAIN, it lists it as a “Dependant SubQuery” which I’m led to believe is bad?

SELECT Competition.CompetitionID, Competition.CompetitionName,     Competition.CompetitionStartDate  
FROM Competition  
WHERE CompetitionID NOT   
IN (  
SELECT CompetitionID  
FROM PicksPoints  
WHERE UserID =1    
)

I tried changing the query to this:

SELECT Competition.CompetitionID, Competition.CompetitionName,   Competition.CompetitionStartDate  
FROM Competition  
LEFT JOIN PicksPoints ON Competition.CompetitionID = PicksPoints.CompetitionID  
WHERE UserID =1  
and PicksPoints.PicksPointsID is null  

but it displays 0 rows. What is wrong with the above compared to the first query that actually does work?

  • 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-08T02:07:51+00:00Added an answer on June 8, 2026 at 2:07 am

    The seconds query cannot produce rows: it claims:

    WHERE UserID =1  
    and PicksPoints.PicksPointsID is null 
    

    But to clarify, I rewrite as follows:

    WHERE PicksPoints.UserID =1  
    and PicksPoints.PicksPointsID is null 
    

    So, on one hand, you are asking for rows on PicksPoints where UserId = 1, but then again you expect the row to not exist in the first place. Can you see the fail?

    External joins are so tricky at that! Usually you filter using columns from the “outer” table, for example Competition. But you do not wish to do so; you wish to filter on the left-joined table. Try and rewrite as follows:

    SELECT Competition.CompetitionID, Competition.CompetitionName,   Competition.CompetitionStartDate  
    FROM Competition  
    LEFT JOIN PicksPoints ON (Competition.CompetitionID = PicksPoints.CompetitionID AND UserID = 1)
    WHERE 
    PicksPoints.PicksPointsID is null  
    

    For more on this, read this nice post.

    But, as an additional note, performance-wise you’re in some trouble, using either subquery or the left join.

    With subquery you’re in trouble because up to 5.6 (where some good work has been done), MySQL is very bad with optimizing inner queries, and your subquery is expected to execute multiple times.

    With the LEFT JOIN you are in trouble since a LEFT JOIN dictates the order of join from left to right. Yet your filtering is on the right table, which means you will not be able to use an index for filtering the USerID = 1 condition (or you would, and lose the index for the join).

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

Sidebar

Related Questions

So I finally got my listview to display result(s) from my db query, but
I have a SQL query in which I will be passing dd/mm/yyyy but the
I'm having trouble getting any information to display from this query. Anyone know where
This Query is giving me an error of #1054 - Unknown column 'totalamount' in
this query SELECT * FROM tblContracts LEFT JOIN tblPartys ON tblContracts.id = tblPartys.Contract_id INNER
This query is somewhat related to this earlier one on sorting where, it was
This query works fine for me: $query = SELECT p.topnode_id, p.param_key, p.param_value FROM tbl_params
This query gives me syntax error in when-between line. how can i solve them?
This query selects all the unique visitor sessions in a certain date range: select
This query works: item = db.GqlQuery(SELECT * FROM Item WHERE CSIN = 13)[0] although

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.