Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add the result of SELECT query in another SELECT query

This is the result of a UNION of two SELECT

SELECT count(*) FROM
((SELECT session_id_current_user from test.tws_analytics 
        WHERE (add_date BETWEEN '2022-05-15' AND '2022-05-15') AND ((pathURL='vues/login.php' AND name_current_user='') OR (pathURL='' AND searchURL='?job=forgotten' AND name_current_user=''))
        AND session_id_current_user NOT IN 
        (SELECT session_id_current_user from test.tws_analytics 
        WHERE (pathURL <> 'vues/login.php' AND searchURL <> '?job=forgotten') AND add_date BETWEEN '2022-05-15' AND '2022-05-15' order by session_id_current_user)
        order by session_id_current_user)
    UNION 
(SELECT name_current_user from test.tws_analytics where add_date BETWEEN '2022-05-15' AND '2022-05-15' AND name_current_user IS NOT NULL AND name_current_user <> ''))
AS tem

The result is 11.

What I want to do is to select this result with other columns like this :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT count(session),count(name), [AND tem.count(*)] FROM ....

This is the general idea, though i didn’t know how to implement it.

>Solution :

a simplified general answer would be

select * from (select count(*) numsessions from sessions), (select count(*) numusers from users)

this will give 2 different counts, i didn’t include the logics that you provided, but that will need to be done inside the 2 subqueries.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading