It seems the "NATURAL JOIN" syntax does not work terribly well in my PHP5.3 environment. I use PDO to access the SQLite3 engine.
See the example below, where I want to store various access rights for users :
CREATE TABLE user (
id_u integer PRIMARY KEY,
name text);
CREATE TABLE access (
id_a integer PRIMARY KEY,
id_u integer,
area text,
granted text,
FOREIGN KEY(id_u) REFERENCES user(id_u));
After some instertions, the tables contain this:
id_u name
---- ------
1 Igor
2 Rebecca
id_a id_u area granted
---- ---- ------- -------
1 1 kitchen full
2 2 kitchen restricted
3 1 lab forbidden
Now if I perform this query :
SELECT granted FROM user U
INNER JOIN access A USING (id_u)
WHERE U.name='Igor' and A.area='kitchen';
I get the expected result (full
)
However, this query:
SELECT granted FROM user U
NATURAL INNER JOIN access A
WHERE U.name='Igor' and A.area='kitchen';
yields no result.
Is there something wrong with the second query, or are PDO and/or SQLite3 acting funny here?
EDIT: as requested, I added an SQLfiddle to demonstrate the problem
It works under the two variants of SQLite, but nevertheless it fails in my own environment. Whether there is something wrong with the specific PDO interface, the SQLite version or the way I send my requests, I have no idea. That's where a bit of help would be appreciated.