[thelist] OT turn off the internet

rudy r937 at interlog.com
Thu Jun 28 22:26:23 CDT 2001



need two separate sets of info from two separate database tables,
but the tables aren't related?

don't run two separate queries, make them subqueries of a "fullselect"
(fancy name for two queries UNIONed together) --

   select 1, foocolumn, fooextra
     from footable
    where foofoo= "something"
  union all
   select 2, barcolumn, null
     from bartable
    where barbar = "somethingelse"

passing one fullselect query to the database is more efficient than passing
two separate queries, even thought the database ends up doing the same
amount of work, you avoid the second inter-server communication

in a UNION, the columns have to be "union compatible" which means
the same number of columns of the same datatype in each respective
column position -- use nulls where there is no similar column
(e.g. needed fooextra, didn't need anything extra from bartable)

notice that i've used UNION ALL to avoid the sort which would be
required to eliminiate duplicate rows -- by using numeric literals 1
and 2 to distinguish the rows in the single result table that came from the
different subqueries, i know there will never be duplicate rows arising
from the different subqueries (although either subquery could generate
duplicates, but i'm letting them through), and i simply use 1 and 2 to tell
me which table each row came from...



To make things easier for all of us, please notice this Important Notice
About Notices. You may have noticed the increased number of notices for you
to notice. I've noticed that some of my notices have been noticed. On the
other hand, some of my notices have not been noticed. This is very
noticeable. It is noticed that the responses to the notices have been
noticeably unnoticeable. This notice is to remind you to notice the notices
and respond to the Notices because I do not want the notice to go

Thank you!

end of Off Topic stuff


More information about the thelist mailing list