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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:47:46+00:00 2026-06-01T16:47:46+00:00

Lets say I have a table A with columns (Alpha, Beta) which is linked

  • 0

Lets say I have a table A with columns (Alpha, Beta) which is linked to table B with columns (Beta, Delta, Gamma). I can’t explain why the first query is transformed to a cross join. (A.Alpha, A.Beta and B.Delta are unique keys. B.Beta looks up to A.Beta).

If I do a select like this:

SELECT A.Alpha, B_Alias.Gamma FROM A 
LEFT JOIN B as B_Alias ON B_Alias.Delta = (
  SELECT TOP 1 B_Alias.Delta FROM B 
  WHERE B.Beta = B_Alias.Beta
  ORDER BY B.Gamma desc)
where A.Alpha = 1

The result is many rows, A.Alpha always is equal to the single row selected and B_Alias.Gamma has every Gamma. If I take out the A.Alpha = 1, then it is a full cross join. The attempt by the writer of the query was to get the most recent B column (if any exists) associated with A. I fixed it to work by using the following. I was just wondering if someone can explain why the above works that way.

-- This is the correct query
SELECT A.Alpha, B_Alias.Gamma FROM A 
-- Actually join the A and B tables
LEFT JOIN B on B.Beta = A.Beta and B.Delta = (
  -- Only get the Most Recent B for any given A
  SELECT TOP 1 B.Delta FROM B 
  WHERE B.Beta = A.Beta
  ORDER BY B.Gamma desc)
where A.Alpha = 1
  • 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-01T16:47:47+00:00Added an answer on June 1, 2026 at 4:47 pm

    The top query has no condition in the ON clause that relates A to B. What you’re doing is taking every row from B that has the top Delta ordered by Gamma for it’s Beta row, and joining that result set to each row from A. You’re essentially taking a subset of B (Which will be equal to B if Beta is unique) and cross joining it to A because you haven’t specified any direct relationship between A and B.

    Just as a bit more detail, if you take any table and join it to any other table where you have no TableA.SomeColumn = TableB.SomeColumn, you’ll essentially just get the full result set from TableB that can be limited, and then join that full result set to every row in TableA, because it has no way to limit the result set joined to a row in TableA. I hope that helps.

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

Sidebar

Related Questions

Lets say I have a database table which consists of three columns: id ,
Ok, so lets say I have a table comprising three columns. The first column
Lets say I have table with following columns 1. Client - string. 2. Profit
Lets say I have a table with columns such as: ID Name City State
Lets say I have table named Place with columns: placeId int not null auto_increment,
Lets say I have a table with the following columns: Qty, INTEGER SaleDate, DATETIME
For examples sake, lets say I have a table containing these columns ID (primary
Lets say I have a table with just two columns: name and mood .
Lets say I have a table called Gamers. Gamers contains the columns GamerID ,
lets say I have a table called table1 and it's corresponding columns are col1,

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.