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
AND
o.client_id = u.user_id;
I get this error:
You have an arror in your SQL syntax '' at line 1
As you see, this error message have nothing to do
with the stucture of my tables or with what they contain.
SYNTAX ERROR ???????????????????
Help! 14 3050
"syntax error" means that what you wrote is not within the syntax that mysql
use, occures very often when you
write something wrong or just have the wrong order in stuff and so on
in this case I think it's because u referes to the alias u and o of the
table before u alias them
it should just be select * from ....
"sam" <rb*****@caramail.com> wrote in message
news:bl**********@news.cybercity.dk... 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 AND o.client_id = u.user_id;
I get this error:
You have an arror in your SQL syntax '' at line 1
As you see, this error message have nothing to do with the stucture of my tables or with what they contain. SYNTAX ERROR ???????????????????
Help!
[ not posted to alt.php.sql ]
sam wrote: 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 AND o.client_id = u.user_id;
I get this error:
You have an arror in your SQL syntax '' at line 1
As you see, this error message have nothing to do with the stucture of my tables or with what they contain. SYNTAX ERROR ???????????????????
Help!
Are you including the semicolon in the string?
Don't!
<?php
$errsql = 'select * from table;';
$goodsql = 'select * from table';
?>
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
On 29-Sep-2003, "sam" <rb*****@caramail.com> wrote: 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 AND o.client_id = u.user_id;
I get this error:
You have an arror in your SQL syntax '' at line 1
As you see, this error message have nothing to do with the stucture of my tables or with what they contain. SYNTAX ERROR ???????????????????
Help!
I ran the sql string (including the ;) as you wrote it and it does not get a
syntax error. This suggests that you aren't getting the sql string to MySQL
intact. Please post the code that defines the sql string and does the query.
--
Tom Thackrey www.creative-light.com
Tom Thackrey wrote:
[...] I ran the sql string (including the ;) as you wrote it and it does not get a syntax error. This suggests that you aren't getting the sql string to MySQL intact. Please post the code that defines the sql string and does the query.
Oops ... I failed to test the semicolon (no error for me either).
You may want to check the sql error message:
<?php
// connect to database
$sql = "select * from table";
$res = mysql_query($sql)
or die(mysql_error() . ' in [' . $sql . ']');
// rest of script
?>
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
In article <bl**********@news.cybercity.dk>,
"sam" <rb*****@caramail.com> wrote: FROM users u, orders o
users AS u, orders AS o ?
Just guessing,
JP
--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
On Mon, 29 Sep 2003 12:35:42 +0200, "sam" <rb*****@caramail.com> wrote: 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 AND o.client_id = u.user_id;
I get this error:
You have an arror in your SQL syntax '' at line 1
As you see, this error message have nothing to do with the stucture of my tables or with what they contain. SYNTAX ERROR ???????????????????
Post the surrounding PHP; are you sure that statement is actually what is
being executed?
--
Andy Hassall (an**@andyh.co.uk) icq(5747695) ( http://www.andyh.co.uk)
Space: disk usage analysis tool ( http://www.andyhsoftware.co.uk/space)
"sam" <rb*****@caramail.com> wrote in message
news:<bl**********@news.cybercity.dk>... 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 AND o.client_id = u.user_id;
I get this error:
You have an arror in your SQL syntax '' at line 1
As you see, this error message have nothing to do with the stucture of my tables or with what they contain. SYNTAX ERROR ???????????????????
Yes, it is a syntax error, right there in the first line of your
query. If a query is based on more than one table, you can't use
* as it leads to naming conflicts. To fix this error, you will
have to explicitly specify all fields you want to obtain, preferably
with an alias for each field.
Also, using WHERE o.client_id = u.user_id is commonly considered
bad style. A better idea is to use o.client_id = u.user_id as
a join condition.
So your query should be rewritten along the following lines:
SELECT
u.field1 AS u_field1,
u.field2 AS u_field2,
u.field3 AS u_field3,
o.field1 AS o_field1,
o.field2 AS o_field2,
o.field3 AS o_field3
FROM users u LEFT JOIN orders o
ON o.client_id = u.user_id
WHERE
TO_DAYS(o.order_date)
BETWEEN
TO_DAYS('2003-09-20')-10
AND
TO_DAYS('2003-09-20')+10;
Cheers,
NC
On 29 Sep 2003 11:36:52 -0700, nc@iname.com (Nikolai Chuvakhin) wrote: "sam" <rb*****@caramail.com> wrote in message news:<bl**********@news.cybercity.dk>... 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 AND o.client_id = u.user_id;
I get this error:
You have an arror in your SQL syntax '' at line 1
As you see, this error message have nothing to do with the stucture of my tables or with what they contain. SYNTAX ERROR ??????????????????? Yes, it is a syntax error, right there in the first line of your query. If a query is based on more than one table, you can't use * as it leads to naming conflicts. To fix this error, you will have to explicitly specify all fields you want to obtain, preferably with an alias for each field.
No, that's not a syntax error, you just lose fields on the way into PHP.
mysql> select t1.*, t2.* from t1, t2;
+------+------+
| id | id |
+------+------+
| 1 | 1 |
+------+------+
1 row in set (0.00 sec)
Also, using WHERE o.client_id = u.user_id is commonly considered bad style. A better idea is to use o.client_id = u.user_id as a join condition.
So your query should be rewritten along the following lines:
SELECT u.field1 AS u_field1, u.field2 AS u_field2, u.field3 AS u_field3, o.field1 AS o_field1, o.field2 AS o_field2, o.field3 AS o_field3 FROM users u LEFT JOIN orders o ON o.client_id = u.user_id
Why use LEFT JOIN? Surely you mean [INNER] JOIN; why go for an outer join
unless you actually need one?
--
Andy Hassall (an**@andyh.co.uk) icq(5747695) ( http://www.andyh.co.uk)
Space: disk usage analysis tool ( http://www.andyhsoftware.co.uk/space)
On 29-Sep-2003, nc@iname.com (Nikolai Chuvakhin) wrote: SELECT u.*, o.* FROM users u, orders o
(snip) Yes, it is a syntax error, right there in the first line of your query. If a query is based on more than one table, you can't use * as it leads to naming conflicts. To fix this error, you will have to explicitly specify all fields you want to obtain, preferably with an alias for each field.
Wrong. u.*, o.* works as coded.
--
Tom Thackrey www.creative-light.com
I noticed that Message-ID:
<u5*******************@newssvr13.news.prodigy.co m> from Tom Thackrey
contained the following: Wrong. u.*, o.* works as coded.
How is it different from SELECT * ?
--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
On 29-Sep-2003, Geoff Berrow <bl@ckdog.co.uk.the.cat> wrote: Wrong. u.*, o.* works as coded.
How is it different from SELECT * ?
It allows you to select all the columns from one table (i.e.
u.*,o.name,o.price) where * selects all columns from all tables.
--
Tom Thackrey www.creative-light.com
I noticed that Message-ID:
<Ds****************@newssvr27.news.prodigy.com> from Tom Thackrey
contained the following: >Wrong. u.*, o.* works as coded.
How is it different from SELECT * ?
It allows you to select all the columns from one table (i.e. u.*,o.name,o.price) where * selects all columns from all tables.
I can see that. But in this instance, no difference, surely?
--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
On 29-Sep-2003, Geoff Berrow <bl@ckdog.co.uk.the.cat> wrote: >Wrong. u.*, o.* works as coded.
How is it different from SELECT * ?
It allows you to select all the columns from one table (i.e. u.*,o.name,o.price) where * selects all columns from all tables.
I can see that. But in this instance, no difference, surely?
None, but it didn't cause the syntax error either.
--
Tom Thackrey www.creative-light.com
Thanks guys for your help,
The problem was:
My query string contains a ' in the wrong place.
THANKS.
"sam" <rb*****@caramail.com> wrote in message
news:bl**********@news.cybercity.dk... 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 AND o.client_id = u.user_id;
I get this error:
You have an arror in your SQL syntax '' at line 1
As you see, this error message have nothing to do with the stucture of my tables or with what they contain. SYNTAX ERROR ???????????????????
Help!
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ian justice |
last post by:
Before i post actual code, as i need a speedyish reply.
Can i first ask if anyone knows off the top of their head, if there is
a likely obvious cause to the following problem.
For the moment i've...
|
by: atse |
last post by:
Hi,
My table in the database may contain duplicate records, which means except
the primary key (auto_increment) field is unique, all or almost of all the
fields are with the same content. How...
|
by: Kevin |
last post by:
Hi, I am getting a syntax error
Microsoft VBScript compilation error '800a03ea'
Syntax error
On the code below. The error references the "End Select" line
Can anyone help me with what I am...
|
by: Omavlana |
last post by:
Hi,
I want to create a temporary table and store the logdetails from
a.logdetail column.
select a.logdetail , b.shmacno
case when b.shmacno is null then
select...
|
by: Jan Schmidt |
last post by:
Hi NG,
i've got a mystic problem i can't solve, perhaps one of you has a good idea...
i will explain with some code, so fo better understanding my probroblem:
i'll use asp, but for testing the...
|
by: Tcs |
last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't
loaded it yet. I'm still using MS Access. And no, I don't believe this is an
Access question. (But who knows? I...
|
by: yrrah |
last post by:
Hello, i've a problem regarding the select stmt inside the stored procedure.
Here's my code:
DELIMITER $$
DROP PROCEDURE IF EXISTS `p`.`getNames`$$
CREATE PROCEDURE `p`.`getNames`(q...
|
by: trose178 |
last post by:
Good day all, I am working on a multi-select list box for a standard
question checklist database and I am running into a syntax error in
the code that I cannot seem to correct. I will also note...
|
by: kxyz |
last post by:
Hello everyone,
I need help with a stored procedure or two.
My stored procedures are supposed to check if a certain record exists. If it does exist, then I select everything from that row, as...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |