Combine Select Statement

rockyy

Active member
Joined
Feb 3, 2010
Messages
25
Programming Experience
Beginner
i have a table session ,
as i have to run two select statements everytime which shows the result sof online user's and username and status
is it possible to combine both the statement in a single statement or any other method

query 1
VB.NET:
Expand Collapse Copy
select username ,status from session where status='online'

query 2
VB.NET:
Expand Collapse Copy
select count(status) from session where status='online'
 
VB.NET:
Expand Collapse Copy
SELECT Username, Status FROM Session WHERE Status = 'online' UNION SELECT NULL AS Username, COUNT(Status) FROM Session WHERE Status = 'online';
You should add the key field to this query too. Also parametrizing it would be a good idea too.
 
its giving me conversion error
xmqu8m.jpg
 
Read the error message. It's not the union query it's the Status field, which is an integer and you're looking for a string.
 
Back
Top