Question:
Is it possible to display the result of multiple SQL query in a single table?
Toots
2010-06-08 06:46:52 UTC
Hi! I have the following in my query
SELECT fAvailmentBranch, Count(fAvailmentBranch) AS NUMBER_OF_CLIENTS FROM Appointments WHERE fDate=#6/8/2010# Group By fAvailmentBranch

The above displays a two-column table. The first column shows the name of the branch while the second column shows the number of clients per branch in a specific date, in this case 06/8/2010.

Now, what's the SQL query to display the same data as above but this time with 5 specific dates instead of just one?

Thanks in advance =)
Five answers:
ʃοχειλ
2010-06-08 07:10:46 UTC
I approved both previous answers, especially Matt's answer.



There are occasions which you are dealing with extracting similar info from different tables. In this case, you would need to write really multiple queries. If you want to accumulate the results in a single table, you could write a user-defined table function.
2016-06-03 06:24:56 UTC
How many tables are you talking about? Will you always know what the tables are? Are you doing it to every table in a database? You can loop in SQL Server. But if you know what the tables are and they're not going to change it's going to be easier to just.. truncate table table1; truncate table table2; truncate table table3; truncate table table4; truncate table table5;
TheMadProfessor
2010-06-10 07:33:01 UTC
Try this:



SELECT fAvailmentBranch, fDate, Count(fAvailmentBranch) AS NUMBER_OF_CLIENTS FROM Appointments WHERE fDate BETWEEN #date1# AND #date2# Group By fAvailmentBranch, fdate



If the 5 dates are not contiuous, include them in a list instead and use IN instead of BETWEEN.
no1home2day
2010-06-08 06:59:50 UTC
Change the "WHERE" clause to include more dates, or remove the "WHERE clause in order to see ALL the dates.



But this isn't "multiple SQL query" a multiple SQL query would involve a "JOIN" clause, connecting two tables by a mutual KEY (the same value in this one field in both tables). If you want ALL the values in Table1 along with their corresponding fields in Table2, you would use an "OUTER JOIN" or a "RIGHT OUTER JOIN" so that two tables are combined.
2010-06-08 06:59:52 UTC
Where fDate in ( date1, date2, ..., date5 )


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...