Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While I basically agree with the other answers that I have seen here, I am going to take a different tack with my answer: </p> <p>If you are trying to learn SQL, then it is imperative that you discipline yourself to use better formmating. This may seem petty, but in truth you will find it easy to read, understand and <em>especially</em> edit if you use more understandable formatting. </p> <p>And while I really miss c/c++ type block-quotes in c#, decades of VB programming have acclimated me to the somewhat ugly requirements of this without them. Compare your example:</p> <blockquote> <p>txt = "SELECT * from D1Table WHERE Synopsis LIKE '%" + txtBText + "%' OR Author1 LIKE '%" + txtBText + "%' OR Author2 LIKE '%" + txtBText + "%' OR Author3 LIKE '%" + txtBText + "%' OR Author4 LIKE '%" + txtBText + "%' OR Author5 LIKE '%" + txtBText + "%' OR Biography1 LIKE '%" + txtBText + "%' OR Biography2 LIKE '%" + txtBText + "%' OR Biography3 LIKE '%" + txtBText + "%' OR Biography4 LIKE '%" + txtBText + "%' OR Biography5 LIKE '%" + txtBText + "%' OR Title LIKE '%" + txtBText + "%' OR Position1 LIKE '%" + txtBText + "%'OR Position2 LIKE '%" + txtBText + "%' OR Position3 LIKE '%" + txtBText + "%' OR Position4 LIKE '%" + txtBText + "%' OR Position5 LIKE '%" + txtBText + "%' "; </p> </blockquote> <p>to its equivalent:</p> <pre><code>txt = "" + " SELECT * " + " from D1Table " + " WHERE Synopsis LIKE '%" + txtBText + "%' " + " OR Author1 LIKE '%" + txtBText + "%' " + " OR Author2 LIKE '%" + txtBText + "%' " + " OR Author3 LIKE '%" + txtBText + "%' " + " OR Author4 LIKE '%" + txtBText + "%' " + " OR Author5 LIKE '%" + txtBText + "%' " + " OR Biography1 LIKE '%" + txtBText + "%' " + " OR Biography2 LIKE '%" + txtBText + "%' " + " OR Biography3 LIKE '%" + txtBText + "%' " + " OR Biography4 LIKE '%" + txtBText + "%' " + " OR Biography5 LIKE '%" + txtBText + "%' " + " OR Title LIKE '%" + txtBText + "%' " + " OR Position1 LIKE '%" + txtBText + "%' " + " OR Position2 LIKE '%" + txtBText + "%' " + " OR Position3 LIKE '%" + txtBText + "%' " + " OR Position4 LIKE '%" + txtBText + "%' " + " OR Position5 LIKE '%" + txtBText + "%' " ; </code></pre> <p>Clearly easier to read and easier to understand. What's not immediately apparent is that its also easier to edit. Consider that you need to check two tables by adding a UNION:</p> <pre><code>txt = "" // &lt;CUT from here + " SELECT * " + " from D1Table " + " WHERE Synopsis LIKE '%" + txtBText + "%' " + " OR Author1 LIKE '%" + txtBText + "%' " + " OR Author2 LIKE '%" + txtBText + "%' " + " OR Author3 LIKE '%" + txtBText + "%' " + " OR Author4 LIKE '%" + txtBText + "%' " + " OR Author5 LIKE '%" + txtBText + "%' " + " OR Biography1 LIKE '%" + txtBText + "%' " + " OR Biography2 LIKE '%" + txtBText + "%' " + " OR Biography3 LIKE '%" + txtBText + "%' " + " OR Biography4 LIKE '%" + txtBText + "%' " + " OR Biography5 LIKE '%" + txtBText + "%' " + " OR Title LIKE '%" + txtBText + "%' " + " OR Position1 LIKE '%" + txtBText + "%' " + " OR Position2 LIKE '%" + txtBText + "%' " + " OR Position3 LIKE '%" + txtBText + "%' " + " OR Position4 LIKE '%" + txtBText + "%' " + " OR Position5 LIKE '%" + txtBText + "%' " // CUT to here&gt; // VV add a UNION + " UNION ALL " // &lt;PASTE here + " SELECT + " + " from D2Table " // &lt;-- change the table name here + " WHERE Synopsis LIKE '%" + txtBText + "%' " + " OR Author1 LIKE '%" + txtBText + "%' " + " OR Author2 LIKE '%" + txtBText + "%' " + " OR Author3 LIKE '%" + txtBText + "%' " + " OR Author4 LIKE '%" + txtBText + "%' " + " OR Author5 LIKE '%" + txtBText + "%' " + " OR Biography1 LIKE '%" + txtBText + "%' " + " OR Biography2 LIKE '%" + txtBText + "%' " + " OR Biography3 LIKE '%" + txtBText + "%' " + " OR Biography4 LIKE '%" + txtBText + "%' " + " OR Biography5 LIKE '%" + txtBText + "%' " + " OR Title LIKE '%" + txtBText + "%' " + " OR Position1 LIKE '%" + txtBText + "%' " + " OR Position2 LIKE '%" + txtBText + "%' " + " OR Position3 LIKE '%" + txtBText + "%' " + " OR Position4 LIKE '%" + txtBText + "%' " + " OR Position5 LIKE '%" + txtBText + "%' " // ^^ change these column names if needed ; </code></pre> <p>What's left out of here is that for a UNION, the SELECT's must return the same number of columns and the data-types of the columns must be compatible. So if D1Table and D2Table have different columns, then you'll have to remove the "*" and make compatible column-lists for each SELECT.</p>
    singulars
    1. This table or related slice is empty.
    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. 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