MySQL Forums
Forum List  »  Newbie

Re: Results change when embedding sub-queries
Posted by: Rick James
Date: July 14, 2016 02:06PM

    select  count(ext.stbId), count(inv.stbId)
        from  
          ( SELECT  *
                from  aaa.extendeddata
                where  aaa.extendeddata.stbId in ('R1881445299')
          ) as ext,
          ( SELECT  *
                from  aaa.invidifilelist
                where  aaa.invidifilelist.stbId in ('R1881445299')
          ) as inv;

Use the JOIN ... ON syntax.

Don't specify anything in COUNT(...) unless you are trying to avoid NULLs. Simply say COUNT(*).

In newer versions, IN(single-item) is just as fast as = single item.

Perhaps this is what you want?

    select 
        ( SELECT COUNT(*)
                from  aaa.extendeddata
                where  aaa.extendeddata.stbId in ('R1881445299')
        ) as ext,
        ( SELECT COUNT(*)
                from  aaa.invidifilelist
                where  aaa.invidifilelist.stbId in ('R1881445299')
        ) as inv;

It gives one row with 2 columns, the counts from each table. And it is reasonably efficient.

Options: ReplyQuote


Subject
Written By
Posted
Re: Results change when embedding sub-queries
July 14, 2016 02:06PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.