Код: Выделить всё
select
authors.*,
(select count(*) from books where books.author_id = authors.id) as books_count
from authors
where books_count > 0
Чего я не понимаю?
Код: Выделить всё
select
authors.*,
(select count(*) from books where books.author_id = authors.id) as books_count
from authors
where books_count > 0
Standard SQL doesn't allow you to refer to a column alias in a WHERE clause. This restriction is imposed because when the WHERE code is executed, the column value may not yet be determined.
Код: Выделить всё
SELECT
a.*,
COUNT(*) books_count
FROM
authors a
INNER JOIN books b ON b.author_id = a.id
GROUP BY
a.id
Код: Выделить всё
select
authors.*
from authors
where
(select count(*) from books where books.author_id = authors.id) > 0
Код: Выделить всё
select
authors.*,
(select count(*) from books where books.author_id = authors.id) as books_count
from authors
where
(select count(*) from books where books.author_id = authors.id) > 0
Я же привел запрос, что еще не понятно?