A
Anonymous
Guest
Hi everybody. This is my first post here
I'm trying to build a query to get some info from 3 tables at the same time, but I have some problems.
Let's suppose that these are the tables:
table1
id1
userid
id2
name1
...
table2
id2
name2
...
table3
id3
id1
...
Knowing the value of userid...
(1) I want to get all records from table1 with a certain value in the userid field. Ok, I've done this:
SELECT * FROM table1 WHERE userid = '$userid'
(2) I want to get the value of table2.name2 for each of the record I get with the previous query. I've done this:
SELECT * FROM table1, table2.name2 WHERE userid = '$userid' AND table1.id2 = table2.id2
(3) For each record I get with the previous query I want to COUNT all the rows in table3 where table3.id1 = table1.id1
Here is my problem. I tried with COUNT but it doesn't work. Am I doing something wrong or is not possible to do that?
Can anyone help me?
Thanks in advance
Sergio
I'm trying to build a query to get some info from 3 tables at the same time, but I have some problems.
Let's suppose that these are the tables:
table1
id1
userid
id2
name1
...
table2
id2
name2
...
table3
id3
id1
...
Knowing the value of userid...
(1) I want to get all records from table1 with a certain value in the userid field. Ok, I've done this:
SELECT * FROM table1 WHERE userid = '$userid'
(2) I want to get the value of table2.name2 for each of the record I get with the previous query. I've done this:
SELECT * FROM table1, table2.name2 WHERE userid = '$userid' AND table1.id2 = table2.id2
(3) For each record I get with the previous query I want to COUNT all the rows in table3 where table3.id1 = table1.id1
Here is my problem. I tried with COUNT but it doesn't work. Am I doing something wrong or is not possible to do that?
Can anyone help me?
Thanks in advance
Sergio