Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It sounds like you do want a join, not a union.</p> <p>You don't need to compare anything to do a join. You end up with a cross product if you specify no join condition:</p> <pre><code>SELECT t20.*, t1.* FROM table_with_20_columns AS t20 LEFT OUTER JOIN temp_table_with_1_column AS t1 ON (1=1); </code></pre> <p>When there are zero rows in the temp table, it'll be reported as NULL in the result of the above query.</p> <p>However, if there are multiple rows in the temp table, you'll get the cross product with the first table. I can't tell from your question what you want.</p> <p><strong>edit:</strong> The join condition expressed in the <code>ON</code> or <code>USING</code> clause should be optional according to the SQL standard, but at least as I test it in MySQL 5.0, it's a syntax error to omit that clause. But you can use <code>ON (1=1)</code>.</p> <p><strong>edit:</strong> Answering your question in the comment:</p> <pre><code>SELECT COALESCE(reqhead_rec.resp_name, dflt.resp_name) AS resp_name FROM (SELECT 'default name' AS resp_name) dflt LEFT OUTER JOIN reqhead_rec ON (1=1) WHERE reqhead_rec.req_no = biglist.req_no AND reqhead_rec.frm = biglist.req_frm INTO TEMP grabname WITH NO LOG; </code></pre> <p>Actually, you may be able to skip the temp table altogether. Just LEFT JOIN your main table to <code>reahead_rec</code>. Put those conditions into the <code>ON</code> clause of the join, not in the <code>WHERE</code> clause. Then use <code>COALESCE()</code> in the select-list of that query to give a default name when one is not found in the other table.</p> <pre><code>SELECT b.*, COALESCE(r.resp_name, 'default name') AS resp_name FROM biglist AS b LEFT OUTER JOIN reqhead_rec AS r ON (b.req_no = r.req_no AND r.frm = b.req_frm) INTO TEMP xxx WITH NO LOG; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload