0

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!

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

Comments

2

use this

$req = db_query("SELECT count(*) FROM node,node_file WHERE node.nid = node_file.nid AND node.nid = ".$value['nid']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.