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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:50:34+00:00 2026-05-29T03:50:34+00:00

Goodmorning everybody, I’m doing a query in Access 2010 and I’m getting a strange

  • 0

Goodmorning everybody, I’m doing a query in Access 2010 and I’m getting a strange behavior, so I’d like to hear your opinion, here we go:

SELECT X.*, L.CodLinea
FROM (
   SELECT TOP 1 'LBASE' AS CodLinea, 'Linea Base' AS Descrizione FROM ParametriAzienda
)  AS X LEFT JOIN Linee AS L 
ON X.CodLinea = L.CodLinea

The inner query gives always ONE row with two colums that should be something like:

CodLinea  |  Descrizione
----------+--------------
  LBASE   |  Linea Base

Now, doing a left join like above should return ONE row with another column called L.CodLinea with a value that is EQUAL to ‘LBASE’ or NULL depending if the table Linee has got ‘LBASE’ inside. So, the result can be:

  X.CodLinea  |  X.Descrizione  |  L.CodLinea
+-------------+-----------------+--------------+
    LBASE     |  Linea Base     |   LBASE      

if the value exists, or

  X.CodLinea  |  X.Descrizione  |  L.CodLinea
+-------------+-----------------+--------------+
    LBASE     |  Linea Base     |   null      

if the value doesn’t exist. Indeed what I get is:

  X.CodLinea  |  X.Descrizione  |  L.CodLinea
+-------------+-----------------+--------------+
    LBASE     |  Linea Base     |   0          
    LBASE     |  Linea Base     |   0          
    LBASE     |  Linea Base     |   0          
    LBASE     |  Linea Base     |   0          
    LBASE     |  Linea Base     |   0          

That definitely can’t be possible, becasue: a) I should get only one row; b) 0 is NOT equal or like to LBASE. If I use the WHERE instead of LEFT JOIN (similar to an INNER JOIN) the or a RIGHT JOIN, the results are correct (0 rows).

What can be the matter?

EDIT: Actually ParametriAzienda has got only one row and Linee does not contain LBASE value.

  • 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-29T03:50:34+00:00Added an answer on May 29, 2026 at 3:50 am

    The problem is TOP 1: either you have misunderstood its use (bug in your code) or it’s a bug in the engine.

    Personally, I always use DISTINCT because it is Standard SQL (and I understand its use 🙂 Indeed, when I tested this, replacing TOP 1 with DISTINCT turns your actual result into the expected result.

    Here’s my repro. The below VBA creates a new data file in temp folder, with tables and sample data. No references required, simply copy+paste into any VBA module e.g. use Excel:

    Sub NotTop1()
    
      On Error Resume Next
      Kill Environ$("temp") & "\DropMe.accdb"
      On Error GoTo 0
    
      Dim cat
      Set cat = CreateObject("ADOX.Catalog")
    
      With cat
      .Create _
            "Provider=Microsoft.ACE.OLEDB.12.0;" & _
            "Data Source=" & _
            Environ$("temp") & "\DropMe.accdb"
    
        With .ActiveConnection
    
          Dim Sql As String
    
          Sql = _
          "CREATE TABLE ParametriAzienda (x INTEGER NOT NULL);"
          .Execute Sql
    
          Sql = _
          "INSERT INTO ParametriAzienda (x) VALUES (1);"
          .Execute Sql
    
          Sql = _
          "CREATE TABLE Linee (CodLinea CHAR(1) NOT NULL);"
          .Execute Sql
    
          Dim i As Long
          For i = 0 To 4
            Sql = _
            "INSERT INTO Linee (CodLinea) VALUES ('0');"
            .Execute Sql
          Next
    
          Sql = _
          "SELECT X.*, L.CodLinea " & _
          "FROM ( " & _
          "   SELECT TOP 1 'LBASE' AS CodLinea, 'Linea Base' AS Descrizione FROM ParametriAzienda " & _
          ")  AS X LEFT JOIN Linee AS L  " & _
          "ON X.CodLinea = L.CodLinea"
    
      Dim rs
      Set rs = .Execute(Sql)
      MsgBox rs.GetString(2, , vbTab & vbTab, , "<null>")
    
      Sql = Replace$(Sql, "TOP 1", "DISTINCT")
    
      Set rs = .Execute(Sql)
      MsgBox rs.GetString(2, , vbTab & vbTab, , "<null>")        
        End With
        Set .ActiveConnection = Nothing
      End With
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goodmorning, I'm doing a query to fill a MFC Recordset in my program. Since
Goodmorning everybody, I'm having a little problem with a project for school. We are
Goodmorning everybody! I'm not completely new to PHP as in self but still kinda
Good morning everybody! (Yeah I know, that not necessary the morning on your side
Goodmorning lads, First of all - R.I.P TPB! Welcome malaysiabay.org for the Dutchies <3
Good morning, I have mysql queries where I would like to calculate percentage of
the following code #include <iostream> using namespace std; int main(){ char greeting[50] = goodmorning
Good Morning everybody. I'm a beginner in .Net languages and need an example to
Goodmorning coding lads, I'm writing a small regex too clean filenames from special characters
Good morning everybody. I have a question connected with controls and event handling. Lets

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.