Could you tell me how to write this sql, mysql database?

I now have two tables An and B, in which the primary key of table An is a foreign key in B. now I want to query the number of each primary key in A plus all the data in table A. how do you write this?

Mar.07,2022

SELECT
    G.count,A.*
FROM
    (
        SELECT
            COUNT(*) AS count,
            Id
        FROM
            B
        GROUP BY
            Id
    ) G
JOIN A ON G.Id = A.Id;

is not recommended to use associated queries. Sql is written separately. Easy to maintain.


SELECT COUNT (og. order_id ) AS num,o.* FROM va_order o LEFT JOIN va_order_goods og ON o. order_id = og. order_id GROUP BY o. order_id

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eadbc4-46bfd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eadbc4-46bfd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?