473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

LEFT JOIN (SELECT) - Syntax Error In From Clause

Can some one point out to me the error in this sql statement?

Expand|Select|Wrap|Line Numbers
  1. SELECT CommTypes.Description
  2. FROM CommTypes LEFT JOIN 
  3.    (SELECT * 
  4.     FROM IntroducerBasis 
  5.     WHERE IntroducerBasis.IntroducerCode ='AG'
  6.          AND IntroducerBasis.BasisNumber=1) 
  7.        AS Intro
  8.     ON CommTypes.ID = Intro.CommTypeID;
The error highlights the subsequent SELECT statement as the source of the error.

Thanks
Aug 20 '13 #1
4 2999
zmbd
5,501 Expert Mod 4TB
When I recreate what I can based upon your post. This query appears to work; however, I also re-formatted your query so it could be a typo in the SQL. SPACING is IMPORTAINT!

If correcting the spacing in your SQL doesn't help...
Please list your table names, fields, and relationships.
the "*" in the second select masks the information we need.
I suspect there is a typo or missing relationship.

Also we need any error messages, EXACTLY as they appear, including title, and number.

Please use a format like:
tbl_name1
[fieldname_11] Primary Key, autonumber
[fieldname_12] numeric, long; Foriegn Key, 1:M tbl_name2
etc...

tbl_name2
[fieldname_21] Primary Key, autonumber
[fieldname_22] numeric, long; Foriegn Key, 1:M tbl_name3
etc...
Aug 20 '13 #2
redz
12
try this...

Expand|Select|Wrap|Line Numbers
  1. select * 
  2. from
  3.    (SELECT * 
  4.     FROM IntroducerBasis 
  5.     WHERE IntroducerBasis.IntroducerCode ='AG' 
  6.         AND IntroducerBasis.BasisNumber=1) 
  7.       as a
  8.     left join
  9.         (select * 
  10.          from  CommTypes) 
  11.        as b 
  12.     on a.commtypeid = b.id 
  13.  
Aug 22 '13 #3
zmbd
5,501 Expert Mod 4TB
The Query in OP runs fine in my test DB.
Once again I suspect the original SQL has a spacing issue, I inadvertently corrected any such problem when I stepped the SQL. I normally try very hard not to modify anything of that nature; however, I'm human.

REDZ's SQL also works just fine; however a slight modification to REDZ post:
change line 1 from Select *
to
line 1 = SELECT b.Description

This will then return only the CommTypes.[Description] value as in the original post.

It is also best practice end the SQL with a Semi-colon
So change line 12 from on a.commtypeid = b.id
toon a.commtypeid = b.id;

Additionally,
Redz's SQL is essentially the same as OP:
In OP the join is from the CommTypes table to the IntroducerBasis table
Whereas
In the redz sql the join is from the IntroducerBasis table to the CommTypes table

in either case the join conditions appear to be the same and on the same field.
Aug 22 '13 #4
redz
12
Hi zmbd
thanks for editing my query
Aug 27 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: sam | last post by:
When I run this SQL query: SELECT u.*, o.* FROM users u, orders o WHERE TO_DAYS(o.order_date) BETWEEN TO_DAYS('2003-09-20')-10 AND TO_DAYS('2003-09-20')+10
3
by: Allan | last post by:
Please help, below is my problem. Let's say I have 2 tables, a Products table and a Colors table that go as follow: Table Products prodID Name 1 shirt 2 tshirt
3
by: Dave | last post by:
I have a list of towns in tblTownData, and a list of people's names in tblNames. During a year, there are multiple events where more names are added in tblNames, for a particular town. ie:...
14
by: Ryan | last post by:
I want to do the following SQL statement in Access. However, it won't allow me to have the secondary part of my join statement and tells me that this is not supported. OK, so Access doesn't support...
1
by: Antoni Massó Mola | last post by:
Hi, I have two values I receive from a form: strLogin = Request.Form; strPassword = Request.Form; I then need to include it in a Select query to validate the username and password, but the...
2
by: isaac2004 | last post by:
hello i am getting a weird al syntax error from my SQL statement Microsoft OLE DB Provider for ODBC Drivers error '80040e14' Syntax error (missing operator) in query expression...
1
by: darrel | last post by:
hi there can anyone tell me wats wrong with my program, its a like this i have a database called "dbTimescheduling", with a field with a name of "Time",,, for now i want to do is to be able to access...
0
by: CatchSandeepVaid | last post by:
Product and ProductBasic has one-to-one relationship Product ---> ProductID <<PK>> ProductBasic ----> ProductId, useCode, StartTime as composite key..... this startTime's value will be known as...
11
guillermobytes
by: guillermobytes | last post by:
Hi, i'm making a query with PDO and there is a SQL syntax error in it. $sql = 'BAD CODE'; $pdoStmt = $pdo->prepare($sql); if (false === $pdoStmt) { echo 'ERROR'; }
2
by: Pelle Pels | last post by:
Hi. I have three tables KUNDR, ORDRA, ARTIK. I want to have sum of orders, grouped by costumers (KUNDR), and showing all costumers even if no orders that period. My script here works, but its...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.