SQL Server 2012: Multiple select count(column1) in a single query from different table causing errors

Sandeep Sharma

I am trying to fetch counts from different tables in SQL Server 2012.

My query looks like:

SELECT  
    (
        (SELECT COUNT(dbo.Table1.column1) FROM dbo.Table1) AS A,
        (SELECT COUNT(dbo.Table2.column1) FROM ddbo.Table2) AS B,
        (SELECT COUNT(dbo.Table3.column1) FROM dbo.Table3) AS C
    )

I get these errors:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'AS'.

Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'AS'.

Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'AS'.

Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'AS'.

Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'AS'.

Please help me out of this situation.

Giorgi Nakeuri

Change to:

SELECT  
       (Select count(dbo.Table1.column1) from dbo.Table1) AS A,
       (Select count(dbo.Table2.column1) from dbo.Table2) AS B,
       (Select count(dbo.Table3.column1) from dbo.Table3) AS C

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL query to produce multiple top 1 from single table

From Dev

SQL Server: select query from multiple tables

From Dev

How to select halves of multiple groups in a single SQL Server query?

From Dev

SQl query Multiple select statments in the same table under different conditions

From Dev

SQL Server 2012 - Two Table query

From Dev

How to Update Table1 two columns from another table select query in MS SQL Server

From Dev

SQL Server 2012: why different values in where clause would block a select query?

From Dev

Multiple counts on the same SQL Server 2012 table

From Dev

SQL Server - How to SELECT values from different rows but in the same table

From Dev

SQL statement to select join multiple fields from different table?

From Dev

Creating an SQL query with multiple counts and different criteria from one table

From Dev

Select from multiple tables, insert into another table Oracle SQL query

From Dev

Get values from multiple sql server table by one query

From Dev

SQL combining multiple select statements into a single query

From Dev

SQL combining multiple select statements into a single query

From Dev

Rollback in single stored procedure for forloop & insert query in SQL Server 2012

From Dev

SQL Server Exlusive Row Lock Causing Table Select Blocking

From Dev

SQL Server table combination in a single query

From Dev

SQL Server 2012 Query

From Dev

SQL server 2012 - Query on retrieving matching records from a table by cross checking with two other tables

From Dev

SQL Server return multiple queries in a single query

From Dev

How can I select two different values from another table using only a single query?

From Dev

SQL Server 2012 : how to get count group by from multiple table joins

From Dev

Running SSMS for SQL Server 2012 with multiple instances with different collation

From Dev

Running SSMS for SQL Server 2012 with multiple instances with different collation

From Dev

Create table using select query in SQL Server

From Dev

SQL Query: Multiple select and sums on the same table

From Dev

Hibernate with MS SQL Server 2012 issue with table locks and parallel query

From Dev

Update existing table with query results SQL Server 2012

Related Related

  1. 1

    SQL query to produce multiple top 1 from single table

  2. 2

    SQL Server: select query from multiple tables

  3. 3

    How to select halves of multiple groups in a single SQL Server query?

  4. 4

    SQl query Multiple select statments in the same table under different conditions

  5. 5

    SQL Server 2012 - Two Table query

  6. 6

    How to Update Table1 two columns from another table select query in MS SQL Server

  7. 7

    SQL Server 2012: why different values in where clause would block a select query?

  8. 8

    Multiple counts on the same SQL Server 2012 table

  9. 9

    SQL Server - How to SELECT values from different rows but in the same table

  10. 10

    SQL statement to select join multiple fields from different table?

  11. 11

    Creating an SQL query with multiple counts and different criteria from one table

  12. 12

    Select from multiple tables, insert into another table Oracle SQL query

  13. 13

    Get values from multiple sql server table by one query

  14. 14

    SQL combining multiple select statements into a single query

  15. 15

    SQL combining multiple select statements into a single query

  16. 16

    Rollback in single stored procedure for forloop & insert query in SQL Server 2012

  17. 17

    SQL Server Exlusive Row Lock Causing Table Select Blocking

  18. 18

    SQL Server table combination in a single query

  19. 19

    SQL Server 2012 Query

  20. 20

    SQL server 2012 - Query on retrieving matching records from a table by cross checking with two other tables

  21. 21

    SQL Server return multiple queries in a single query

  22. 22

    How can I select two different values from another table using only a single query?

  23. 23

    SQL Server 2012 : how to get count group by from multiple table joins

  24. 24

    Running SSMS for SQL Server 2012 with multiple instances with different collation

  25. 25

    Running SSMS for SQL Server 2012 with multiple instances with different collation

  26. 26

    Create table using select query in SQL Server

  27. 27

    SQL Query: Multiple select and sums on the same table

  28. 28

    Hibernate with MS SQL Server 2012 issue with table locks and parallel query

  29. 29

    Update existing table with query results SQL Server 2012

HotTag

Archive