Not sure what variant of SQL you're using, but you ought to be able to simplify the query:

SELECT s.*, o.waybill, o.shipvia FROM shipto s, oe o WHERE trans_id = $form->{"$form->{vc}_id"} AND to_date(s.shiptophone, 'YYYY-MM-DD') >= to_date(to_char(current_ +timestamp,'YYYY-MM-DD'), 'YYYY-MM-DD') UNION SELECT s.*, o.waybill, o.shipvia FROM shipto s JOIN oe o ON (o.id = s.trans_id) WHERE o.$form->{vc}_id = $form->{"$form->{vc}_id"} AND to_date(s.shiptophone, 'YYYY-MM-DD') >= to_date(to_char(current_ +timestamp,'YYYY-MM-DD'), 'YYYY-MM-DD') UNION SELECT s.*, a.waybill, a.shipvia FROM shipto s JOIN $table a ON (a.id = s.trans_id) WHERE a.$form->{vc}_id = $form->{"$form->{vc}_id"} AND to_date(s.shiptophone, 'YYYY-MM-DD') >= to_date(to_char(current_ +timestamp,'YYYY-MM-DD'), 'YYYY-MM-DD')

If you explain what each of those tables has in it and what you're trying to generate, I may be able to suggest a better query structure. Incidently, is there a particular reason why you're storing your dates as timestamps? Dates are easy to manipulate using INTERVAL commands.


In reply to Re^3: Sort in multilevel hash by TJPride
in thread Sort in multilevel hash by gueriniere

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.