x

ERROR #1064 --WHEN TRYING TO RUN A QUERY WITH JOINS

MY QUERY IS AS FOLLOWS:

SELECT C.Customer_Forename, Customer_Surname ,  j.Time , date, s.Staff_Forename , Staff_Surname v.Vehicle_ID, b.Status
From Booking b
INNER JOIN Vehicle v on v.Staff_ID = s.Staff_ID
INNER JOIN Journey j on j.Vehicle_ID = v.Vehicle_ID
INNER JOIN Booking b on b.Journey_ID = j.Journey_ID
INNER JOIN Booking b on b.Customer_ID = c.Customer_ID
Where b.Place_Number = "2000LT20080312"

ERROR MESSAGE IS AS FOLLOWS:

'#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '.Vehicle_ID, b.Status From Booking b INNER JOIN Vehicle v o

There is a chance that you may have found a bug in the SQL parser. Please examine your query closely, and check that the quotes are correct and not mis-matched. Other possible failure causes may be that you are uploading a file with binary outside of a quoted text area. You can also try your query on the MySQL command line interface. The MySQL server error output below, if there is any, may also help you in diagnosing the problem. If you still have problems or if the parser fails where the command line interface succeeds, please reduce your SQL query input to the single query that causes problems, and submit a bug report with the data chunk in the CUT section below: ----BEGIN CUT---- eNp9ksFuozAURff+irvoElwDmRmC1EWGui0VJSmm6TKC1G1IATMQovYzyswH1ySdDKuRLMvvvXvu lZ7M43gee/At+DZCHnmYwmJwpg4RiR70hPhL4eEsePLQ/irqtGllQ4s8o/WmNvawqe1Qm1qwGZuc W9a5phnzJvq4KGQ5BX+rcUbu3sV96GFCGbWZWagX8iBizIWB2TWPEgNLruMe8woBxw/KyOJu5mn3 75SZdeGQxc1ikBhzMZg41EWYV90bCWfRtQdZmXmrTNf9NjUtckgSPOR+Ap/2ftfuVCmb1ZVqZJWW sjfwcWqKrjn0YABb2if58d0/pbtB2NJe7NLn53+wHn4cWyd0T5dyk68LuQouDWRUj3ddS8hVo0r8 VOo1r16QkSCKeIzbeRDhS489VKXxo19wiQsd+LcY62+VzpLv2A767ShOE+P0MXMKHpiMflkcme2o /A9z2tIBWo9rQh43spFatCjStVxFXZnJRqt+65/AwkTfLnMs+88nA164/Q== ----END CUT---- ----BEGIN RAW----

ERROR: C1 C2 LEN: 9 10 393 STR: ’

CVS: $Id: sqlparser.lib.php,v 2.23.2.1 2004/11/10 00:40:48 lem9 Exp $ MySQL: 4.0.20-log USR OS, AGENT, VER: Win IE 7.0 PMA: 2.6.0-pl3 PHP VER,OS: 4.3.8 Linux LANG: en-iso-8859-1 SQL: SELECT C.’Customer_Forename’, ‘Customer_Surname’ , j.’Time’ , ’date’, s.’Staff_Forename’ , ‘Staff_Surname’ v.Vehicle_ID, b.Status

From Booking b INNER JOIN Vehicle v on v.Staff_ID = s.Staff_ID INNER JOIN Journey j on j.Vehicle_ID = v.Vehicle_ID INNER JOIN Booking b on b.Journey_ID = j.Journey_ID INNER JOIN Booking b on b.Customer_ID = c.Customer_ID

Where b.Place_Number = “2000LT20080312”

more ▼

asked Mar 11, 2010 at 01:17 PM in Default

tom 4 gravatar image

tom 4
11 1 1 1

This is MySQL, not SQL Server. There may be people here that know this information, but you might be better served by going to a MySQL discussion group.
Mar 11, 2010 at 01:27 PM Grant Fritchey ♦♦
This may be MySQL - however, i think the main problem resides in the alias of the inner join. That is something that can be helped with here. As for the mysql specific errors, I agree on finding a MySQL resource.
Mar 11, 2010 at 03:38 PM CirqueDeSQLeil
Please note that I have merged your other question with this one.
Mar 11, 2010 at 04:49 PM Matt Whitfield ♦♦
(comments are locked)
10|1200 characters needed characters left

6 answers: sort voted first

This is mySQL but it looks like you should change the second join to the booking table with an AND

I think it should read

SELECT C.’Customer_Forename’, ‘Customer_Surname’ , j.’Time’ , ’date’, s.’Staff_Forename’ , ‘Staff_Surname’ , v.Vehicle_ID, b.Status From Booking b INNER JOIN Vehicle v on v.Staff_ID = s.Staff_ID INNER JOIN Journey j on j.Vehicle_ID = v.Vehicle_ID  AND b.Journey_ID = j.Journey_ID INNER JOIN Customer c on b.Customer_ID = c.Customer_ID
Where b.Place_Number = “2000LT20080312”
more ▼

answered Mar 11, 2010 at 01:33 PM

Fatherjack gravatar image

Fatherjack ♦♦
42.8k 75 79 108

+1 Damn you are too quick for me! :-D
Mar 11, 2010 at 01:34 PM Ian Roke
upvoting this one though there are two viable solutions. I prefer to combine the joins unless there is a good reason to separate them.
Mar 11, 2010 at 03:32 PM CirqueDeSQLeil
(comments are locked)
10|1200 characters needed characters left

You have used the alias 'B' three times for the table "Booking". Use another alias:

SELECT C.Customer_Forename,  Customer_Surname,  j.Time,  date,  s.Staff_Forename,  Staff_Surname,  v.Vehicle_ID,  <one of the Bookings alias>.Status From Booking b INNER JOIN Vehicle v  on v.Staff_ID = s.Staff_ID INNER JOIN Journey j  on j.Vehicle_ID = v.Vehicle_ID INNER JOIN Booking B1  on B1.Journey_ID = j.Journey_ID INNER JOIN Booking b  on B2.Customer_ID = c.Customer_ID Where <one of the Bookings alias>.Place_Number = '2000LT20080312' 
more ▼

answered Mar 11, 2010 at 01:37 PM

Gianluca Sartori gravatar image

Gianluca Sartori
228 1 4

(comments are locked)
10|1200 characters needed characters left

From a SQL perspective you have this...

INNER JOIN Booking b on b.Journey_ID = j.Journey_ID
INNER JOIN Booking b on b.Customer_ID = c.Customer_ID

Wouldn't it be better just to do this?

INNER JOIN Booking b on b.Journey_ID = j.Journey_ID AND b.Customer_ID = c.Customer_ID 
more ▼

answered Mar 11, 2010 at 01:32 PM

Ian Roke gravatar image

Ian Roke
1.7k 30 33 34

(comments are locked)
10|1200 characters needed characters left

I am not submitting a script here because Gianluca and FatherJack have already done that.

I am offering a little clarification.

You have

INNER JOIN Booking b on b.Journey_ID = j.Journey_ID
INNER JOIN Booking b on b.Customer_ID = c.Customer_ID

Both of these joins are using the same alias, which is not permissible in SQL.

Thus changing the alias on the second, of the two joins referenced, will allow the query to complete successfully. Fatherjack implemented an alternative solution which combined both of your join statements, whilst Gianluca corrected the second alias issue and left the joins in tact.

more ▼

answered Mar 11, 2010 at 03:31 PM

CirqueDeSQLeil gravatar image

CirqueDeSQLeil
4.9k 10 11 15

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x376
x70

asked: Mar 11, 2010 at 01:17 PM

Seen: 17697 times

Last Updated: Mar 11, 2010 at 01:28 PM