473,466 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

join problem

Hi,

I have a problem with mysql joins, which are always a bit complicated
to me.
I use mysql version 4.0.25-standard.

This is my SQLstatement, used to check if user #1 has the right to
login:

SELECT users.*, rights.* FROM users
LEFT JOIN join_users_rights ON users.id=join_users_rights.user
LEFT JOIN rights ON join_users_rights.right=rights.id
WHERE ((rights.name='login') AND (users.id='1'))

And this is the error message I get:
#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
'right = rights . id WHERE ( ( rights . name = 'login' ) AND ( u

Where do I go wrong?

Thanks in advance,

Sjoerd Mulder

Dec 20 '05 #1
10 1466
Sjoerd wrote:
'right = rights . id WHERE ( ( rights . name = 'login' ) AND ( u


See the "rights . id"? That should propably be rights.id. Same for
"rights . name".
Dec 21 '05 #2
It would be very nice if you would post your CREATE TABLE statement, along
with some INSERT INTOs. That way we could post a solution that is tested.

Rich
"Sjoerd" <go****@sjoerdmulder.electronischepost.nl> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi,

I have a problem with mysql joins, which are always a bit complicated
to me.
I use mysql version 4.0.25-standard.

This is my SQLstatement, used to check if user #1 has the right to
login:

SELECT users.*, rights.* FROM users
LEFT JOIN join_users_rights ON users.id=join_users_rights.user
LEFT JOIN rights ON join_users_rights.right=rights.id
WHERE ((rights.name='login') AND (users.id='1'))

And this is the error message I get:
#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
'right = rights . id WHERE ( ( rights . name = 'login' ) AND ( u

Where do I go wrong?

Thanks in advance,

Sjoerd Mulder

Dec 21 '05 #3
CREATE TABLE `join_users_rights` (
`id` int(11) NOT NULL auto_increment,
`user` int(11) NOT NULL default '0',
`right` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

CREATE TABLE `rights` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(30) NOT NULL default '',
`description` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;
CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(30) NOT NULL default '',
`password` varchar(32) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

INSERT INTO `rights` VALUES (1, 'login', 'Login', 1, 1);
INSERT INTO `users` VALUES (1, 'sjoerd', 'mypassword');
INSERT INTO `join_users_rights` VALUES (1, 1, 1);

Thanks in advance,

Sjoerd Mulder

Rich Ryan wrote:
It would be very nice if you would post your CREATE TABLE statement, along
with some INSERT INTOs. That way we could post a solution that is tested.

Rich
"Sjoerd" <go****@sjoerdmulder.electronischepost.nl> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi,

I have a problem with mysql joins, which are always a bit complicated
to me.
I use mysql version 4.0.25-standard.

This is my SQLstatement, used to check if user #1 has the right to
login:

SELECT users.*, rights.* FROM users
LEFT JOIN join_users_rights ON users.id=join_users_rights.user
LEFT JOIN rights ON join_users_rights.right=rights.id
WHERE ((rights.name='login') AND (users.id='1'))

And this is the error message I get:
#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
'right = rights . id WHERE ( ( rights . name = 'login' ) AND ( u

Where do I go wrong?

Thanks in advance,

Sjoerd Mulder


Dec 21 '05 #4
No that's not it. See my own statement. Those spaces appear only in the
error message Mysql gives. But thanks.

Dec 21 '05 #5
So what I want to do, is to check if there exists a user #1 with the
right to 'login'. Another solution will also be fine, although I would
like to understand why my query is wrong.

Dec 21 '05 #6
Sjoerd wrote:
CREATE TABLE `rights` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(30) NOT NULL default '',
`description` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ; INSERT INTO `rights` VALUES (1, 'login', 'Login', 1, 1);


The insert doesn't work. There is 3 columns in the table, but insert has
5 columns.

# But if we replace that with:
INSERT INTO `rights` VALUES (1, 'login', 'Login');

# Then we can execute the query you gave in the first message.
# No errors:
mysql> SELECT users.*, rights.* FROM users
-> LEFT JOIN join_users_rights ON users.id=join_users_rights.user
-> LEFT JOIN rights ON join_users_rights.right=rights.id
-> WHERE ((rights.name='login') AND (users.id='1'));
+----+--------+------------+----+-------+-------------+
| id | name | password | id | name | description |
+----+--------+------------+----+-------+-------------+
| 1 | sjoerd | mypassword | 1 | login | Login |
+----+--------+------------+----+-------+-------------+
1 row in set (0.00 sec)

But error messages should not add spaces where you claimed it was added.
I suspect that something changes your query and adds those spaces to it.
Dec 21 '05 #7
You were right about the insert. I gave the wrong create statement:

CREATE TABLE `rights` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(30) NOT NULL default '',
`description` varchar(100) NOT NULL default '',
`defaultvalue` tinyint(1) NOT NULL default '0',
`order` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

The query does give errors though. The error message appears when I
execute the command either in PHP or in PHPMyAdmin.

Could it have to do with a specific MySQL version? A bug? I use mysql
version 4.0.25-standard.

Dec 21 '05 #8
Sjoerd wrote:
You were right about the insert. I gave the wrong create statement:
Tested with new one, works ok with that also.
Could it have to do with a specific MySQL version? A bug? I use mysql
version 4.0.25-standard.


Possible, but unlikely

I have:
Server version: 4.0.24_Debian-10ubuntu2-log

Where do you execute this query? Do you use the MySQL command line tool
for it? If not, try it.
Dec 21 '05 #9
Like I said, via PHP or PHPMyAdmin. I have no access to any command
line tool, unfortunately.

I tested the query on another server on which I host a page: it worked.
I think I will try to work around it with several querys and combine
them in PHP.

Thanks for your help.

Dec 22 '05 #10
I found the problem!
I renamed every instance of 'right' to something else, and then it
worked. It seems that it is a 'reserved' term for mysql, although not
in every version.

Thanks for all your help.

Dec 22 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
2
by: Bruce Duncan | last post by:
I'm a bit new to MySQL (know MS SQL well...and that may be the problem...getting the syntax confused) and I'm having a join problem...can anyone offer some help? Here's my problem: I have table1...
7
by: Greg | last post by:
I'm a quantitative securities analyst working with Compustat data (company fiscal reports and pricing feeds). My coworker came across a problem that we fixed, but I'd like to understand 'why' it...
4
by: Anthony Robinson | last post by:
I was actually just wondering if someone could possibly take a look and tell me what I may be doing wrong in this query? I keep getting ambiguous column errors and have no idea why...? Thanks in...
12
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U...
5
by: jason.evans | last post by:
Hi there. I am having an intrigueing problem. I have a query which left joins another query to itself twice. The original query is derived from a linked table in SQLServer 2000. When I run...
33
by: Steve | last post by:
One of our clients recently upgraded their Office version to 2003. When they tried to run our program (written in Access 2000), they ended up with the wrong data. My coworker and I have tested this...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
18
by: Dave | last post by:
Guys I am really stuck on this one. Any help or suggestions would be appreciated. We have a large table which seemed to just hit some kind of threshold. They query is somewhat responsive when...
3
by: Anila | last post by:
Hi Friends, My problem with Inner join is ... first i joined two tables and i got the result. after that iam trying to join one more table its giving syn tax error in JOIN condition. ...
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
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...
1
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...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.