MySQL - Multi SELECTs in a query

0

I need to get all the columns of a table and a custom column in the same query, I tried this way:

SELECT (SELECT * FROM clans WHERE ID=1), (SELECT COUNT(*) FROM contas WHERE Clan=1) AS Membros;

It is giving error by trying to get more than one column per SELECT.

    
asked by anonymous 19.07.2017 / 01:09

2 answers

0

Resolved.

SELECT *, (SELECT COUNT(*) FROM contas WHERE Clan=1) AS Membros FROM clans WHERE ID=1;
    
19.07.2017 / 01:20
0

You can use JOIN to make your query simpler:

SELECT  
    c.*,
    COUNT(cn.Clan) AS membros
FROM clans c
INNER JOIN contas cn
ON cn.Clan = c.ID
WHERE c.ID = 1
GROUP BY c.ID
    
06.12.2017 / 13:17