# Sql/php



## vipernet (Aug 23, 2007)

Good day all,

Was wondering if anyone could give me a hand with a sql query. I'm trying to make a count from multiple tables and take the results and add them up.

I have tried multiple ways of doing this. I Guess to best explain I can show you a few examples of what I'm trying to do:

My SQL table structure is basically setup like this:

Table 1
Feild_name1 (text)
Feild_name2 (text)

Feild_name1
Ball small
big Ball
Ball

Table 2
Feild_name1 (text)
Feild_name2 (text)

Feild_name1
Coffee large
Coffee small
Coffee xlarge
Coffee xsmall

Here is a basic count query:

```
SELECT COUNT(*) as result FROM table1 where feild_name1 like '%ball%';
```
COUNT result = 3
PHP]SELECT COUNT(*) as result FROM table1 where feild_name2 like '%coffee%';[/PHP]
COUNT result = 4

In my real Database I have about 20+ tables that i want to get a COUNT value and end up with a total COUNT from all Tables.

Here is what i would like to be able to do, but not sure how really:

```
SELECT COUNT(*) as result FROM table1 where feild_name1 like '%ball%' 
UNION SELECT COUNT(*) as result2 FROM table1 where feild_name2 like '%coffee%';
```
Now what i thought this query would result to is:
count result =3,count result2 = 4
but it actually stores only the first result as:
count result =
34
and count result2 = nothing ( actually an error if i ench it using a Var)

All said and done I just want to create a mutliple COUNT on different tables within SQL and Add up the results.

Any direct or hel would be great. I have tried reading up on using INNER JOIN...etc


----------



## tomdkat (May 6, 2006)

Will this help?

Peace...


----------



## vipernet (Aug 23, 2007)

I think that is for SQL 2000, not the same as mysql as far as i know. thanks for the reply though.


----------



## tomdkat (May 6, 2006)

They are using SQL Server in that example. ANSI standard SQL is standard SQL that all ANSI standards compliant RDBMSes will support. Try it out and see if it helps unless that SQL isn't doing a sum in the manner you want/need.

Peace...


----------

