Answer the question
In order to leave comments, you need to log in
Another question on Mysql?
I want to get the number of all records from 3 tables with identical structure where the column is private='0'
I wanted to do it like this:
SELECT COUNT(*) FROM users_data, deleted, mails WHERE private='0'
#1052 - 'private' column in where clause is ambiguous
SELECT COUNT(*) FROM users_data, deleted, mails WHERE users_data.private='0' AND deleted.private='0' AND mails.private='0'
SELECT COUNT(*) FROM users_data WHERE private='0'
Answer the question
In order to leave comments, you need to log in
You have multiplied the tables, getting a very large number of elements. You need to combine the output via UNION.
SELECT SUM(cnt) FROM (
SELECT COUNT(*) as cnt FROM users_data WHERE private='0'
UNION
SELECT COUNT(*) as cnt FROM deleted WHERE private='0'
UNION
SELECT COUNT(*) as cnt FROM mails WHERE private='0'
) u;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question