Reputation: 972
I want to count for each gallery number of images in it, here's my query:
$req = db_query("SELECT count(*) FROM node,node_file WHERE node.nid = node_file.nid AND nid = ".$value['nid']);
here's the two tables :
node_file:
nid |fid |
-------------
1 | 1 |
-------------
1 | 2 |
-------------
1 | 3 |
-------------
2 | 1 |
-------------
2 | 2 |
-------------
2 | 3 |
node:
nid |type |
-------------
1 |Gallery1|
-------------
2 |gallery2|
The error : Query : SELECT count(*) FROM node,node_file WHERE node.nid = node_file.nid AND nid = 34
Message : SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'nid' in where clause is ambiguous
Thanks!
Upvotes: 0
Views: 66
Reputation: 1550
use this
$req = db_query("SELECT count(*) FROM node,node_file WHERE node.nid = node_file.nid AND node.nid = ".$value['nid']);
Upvotes: 2
Reputation: 4888
Both of your tables have column nid
and you are using column in AND
clause so you need to specify to which table it belongs.
SELECT
count(*)
FROM
node,
node_file
WHERE
node.nid = node_file.nid AND node.nid = 34
OR
SELECT
count(*)
FROM
node,
node_file
WHERE
node.nid = node_file.nid AND node_file.nid = 34
Upvotes: 4