How to add multiple requests into a SELECT statement SQL

Viewed 22

How can I request all columns (*) in a table while at the same time counting all distinct items in a id_number column? (Learning SQL Thanks for your help)

1 Answers

You can use WITH to make a sub-query like:

WITH with_tbl_a AS 
     (SELECT * FROM tbl_a) 
     SELECT a.col_1, count(b.pk), etc...
       FROM with_tbl_a
       INNER JOIN tbl_b b ON a.fk = b.pk

Hope that it helps you.

Related