selecting records from main table and count of each row in another table

NetProjects Ir

I have 2 table in my database that tables are in relationship with foreign key I want to select all records from main table and then select count of each row in another table than have same ID from main table I tried to create a select query but it is not work correctly this query return all records from main table + count of all records from next table(not count of each row in relationship)

    SELECT tblForumSubGroups_1.id, tblForumSubGroups_1.GroupID,
    tblForumSubGroups_1.SubGroupTitle, tblForumSubGroups_1.SubGroupDesc,
    (SELECT COUNT(dbo.tblForumPosts.id) AS Expr1
    FROM dbo.tblForumSubGroups INNER JOIN dbo.tblForumPosts ON 
    dbo.tblForumSubGroups.id = dbo.tblForumPosts.SubGroupID) AS Expr1
    FROM dbo.tblForumSubGroups AS tblForumSubGroups_1 INNER JOIN
    dbo.tblForumPosts AS tblForumPosts_1 ON tblForumSubGroups_1.id 
    = tblForumPosts_1.SubGroupID
Vishal Gajjar
SELECT  tblForumSubGroups_1.id, tblForumSubGroups_1.GroupID, tblForumSubGroups_1.SubGroupTitle, tblForumSubGroups_1.SubGroupDesc,
        COUNT(tblForumPosts_1.id) AS Expr1
FROM    dbo.tblForumSubGroups AS tblForumSubGroups_1
INNER JOIN  dbo.tblForumPosts AS tblForumPosts_1 ON tblForumSubGroups_1.id = tblForumPosts_1.SubGroupID
GROUP BY tblForumSubGroups_1.id, tblForumSubGroups_1.GroupID, tblForumSubGroups_1.SubGroupTitle, tblForumSubGroups_1.SubGroupDesc

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Selecting records from a table and then selecting a count of records from another table

From Dev

Selecting records from a table not in another table

From Dev

Count Row from another table

From Dev

Selecting two rows from another table using one row

From Dev

Selecting row from table in laravel

From Dev

Insert row in table for each id from another table

From Dev

Insert row in table for each id from another table

From Dev

SQL query to return records from one table that are associated to 2 records each from another table

From Dev

Selecting entries from a table based on another table

From Dev

Selecting data from one table and joining another table for the main "key" is quite slow

From Dev

Selecting data from one table and joining another table for the main "key" is quite slow

From Dev

Finding records in main table that match records in another table in SQL Server

From Dev

MySQL select Distinct records in 1 table and count each group based on values in another table

From Dev

Selecting top 3 distinct records from a table

From Dev

Selecting SUM+COUNT from one table and COUNT from another in Single query

From Dev

php count and add each values from MySQL table row

From Dev

How to join row count of each group from right side table

From Dev

Selecting one record from two tables and multiple records from another table in ONE query

From Dev

Trying to use subquery to get row count from another table

From Dev

SQL Hide/Show rows based on row count from another table

From Dev

Updating records in table with ID from another table

From Dev

get records without records from another table

From Dev

Selecting row from Table - Java Selenium

From Dev

mySQL - Selecting the latest row from a table

From Dev

MySQL - selecting random row from large table

From Dev

Count number of records and generate row number within each group in a data.table

From Dev

django - how to bind records of table with calculated count values from another table

From Dev

Selecting rows that are included in a set from another table

From Dev

Selecting from 1 Table and Updating in Another

Related Related

  1. 1

    Selecting records from a table and then selecting a count of records from another table

  2. 2

    Selecting records from a table not in another table

  3. 3

    Count Row from another table

  4. 4

    Selecting two rows from another table using one row

  5. 5

    Selecting row from table in laravel

  6. 6

    Insert row in table for each id from another table

  7. 7

    Insert row in table for each id from another table

  8. 8

    SQL query to return records from one table that are associated to 2 records each from another table

  9. 9

    Selecting entries from a table based on another table

  10. 10

    Selecting data from one table and joining another table for the main "key" is quite slow

  11. 11

    Selecting data from one table and joining another table for the main "key" is quite slow

  12. 12

    Finding records in main table that match records in another table in SQL Server

  13. 13

    MySQL select Distinct records in 1 table and count each group based on values in another table

  14. 14

    Selecting top 3 distinct records from a table

  15. 15

    Selecting SUM+COUNT from one table and COUNT from another in Single query

  16. 16

    php count and add each values from MySQL table row

  17. 17

    How to join row count of each group from right side table

  18. 18

    Selecting one record from two tables and multiple records from another table in ONE query

  19. 19

    Trying to use subquery to get row count from another table

  20. 20

    SQL Hide/Show rows based on row count from another table

  21. 21

    Updating records in table with ID from another table

  22. 22

    get records without records from another table

  23. 23

    Selecting row from Table - Java Selenium

  24. 24

    mySQL - Selecting the latest row from a table

  25. 25

    MySQL - selecting random row from large table

  26. 26

    Count number of records and generate row number within each group in a data.table

  27. 27

    django - how to bind records of table with calculated count values from another table

  28. 28

    Selecting rows that are included in a set from another table

  29. 29

    Selecting from 1 Table and Updating in Another

HotTag

Archive