Combine 2 SQL Query results
NickName:hello temp11 Ask DateTime:2015-07-04T03:21:45

Combine 2 SQL Query results

I want to combine my 2 sql results and 1 more filter which is Date. How Can I combine my these 2 sql queries.

First sql

 SELECT e.Name,COUNT(l.userName) as UsersVisit
  FROM Table1 l
  INNER JOIN Table2 e on e.UserName =l.UserName
  WHERE 
  ( l.DateAccessed>'3-31-2015' and l.DateAccessed <'4-30-2015')
  Group by e.Name

O/P I get

Name  UsersVisit
abc    10
xyz    20
def    30

Second Sql

SELECT COUNT(1) as TotalVisits
  FROM Table1 l
  INNER JOIN Table2 e on e.UserName =l.UserName
  WHERE 
  ( l.DateAccessed>'3-31-2015' and l.DateAccessed <'4-30-2015')
  ORDER BY TotalVisits DESC

O/P I get

TotalVisits
60

Now, the O/P I want is

UniqueUsers  TotalVisits  Month
3               60        March
4               50        April

3 is the unique number of users(abc,xyz,def), while TotalVisits is the count of all the UsersVisit

How can I get these result ?

Copyright Notice:Content Author:「hello temp11」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31213078/combine-2-sql-query-results

More about “Combine 2 SQL Query results” related questions

Combine 2 SQL Query results

I want to combine my 2 sql results and 1 more filter which is Date. How Can I combine my these 2 sql queries. First sql SELECT e.Name,COUNT(l.userName) as UsersVisit FROM Table1 l INNER JOIN

Show Detail

Combine Loop Query Results into 1

I have a loop that queries a SP and returns results in a query, I want to combine that query (however many times the loop runs) into one final query so I can output in my jgrid table. Here is the c...

Show Detail

Combine results of 2 SQL queries into 1

I have two sql queries as below 1. ;with test as (.........) select abc from (select ... from test) 2. ;with test1 as (....) select abc from (select ... from test1) Both of the queries ...

Show Detail

How to combine results from a SQL query

I am selecting data from two tables and want to combine my results. I am currently getting the following results - Sales | Purchase | ProName | ProId 0 | 570 | Capital | 1 2125...

Show Detail

How to combine 2 SQL queries

We have 2 SQL queries we use to look up a database lock from a user login, as sometimes we need to unlock it manually. In short, we run the following query, which will return a few results: SELECT

Show Detail

Combine SQL with XQuery and Linq To SQL

How to efficiently combine a direct SQL query and Linq To SQL query? Linq To SQL doesn't support XQuery. So I have to combine the results of a SQL with XQuery and column based Linq To SQL? Any poi...

Show Detail

2 table SQL Query weird results

Ok this is driving me nuts, I need to write an SQL query that will grab product information from 2 tables. The first table 'products' contains the productId, productname, quantityperunit and unitpr...

Show Detail

combine two oracle sql results into single dataset

I have two selects and I want to combine them in such a way, that only one row that has key column matched in both selects are returned(one row in first select and one row in 2nd select). Is there ...

Show Detail

SQL query table 2x then combine results into 1 column

I am working with sqlite and have a language dictionary. I want to search the table once for a match in English then again to find the results in another language by matching foreign keys (to a Jap...

Show Detail

Combine results of 2 Queries

I have a python script that queries DBpedia using 2 SPARQL queries, and, for each of the queries, puts the result in a list. Then I make a set of this list to remove duplicates, and I have the resu...

Show Detail