Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL query to INSERT, UPDATE, or DELETE
    primarykey
    data
    text
    <p><strong>asset_property</strong> table: </p> <pre><code>| asset_id | property_id | property_value | |:--------:|:-----------:|:---------------| | 146 | 1 | 4G | | 146 | 3 | 68723-239Gs | | 147 | 1 | A7 | </code></pre> <p>This is my query:</p> <pre><code>INSERT INTO asset_property (asset_id, property_id, property_value) VALUES (146, 1, '4G'), (146, 2, 'Black &amp; Decker'), (146, 3, ''), ON DUPLICATE KEY UPDATE property_value = VALUES(property_value); </code></pre> <p>Is there a way to say something like this:</p> <pre><code>INSERT INTO asset_property (asset_id, property_id, property_value) VALUES (146, 1, '4G'), (146, 2, 'Black &amp; Decker'), (146, 3, ''), ON DUPLICATE KEY UPDATE property_value = VALUES(property_value) ON VALUES(property_value) IS NULL DELETE FROM asset_property WHERE asset_id = VALUES(asset_id) AND property_id = VALUES(property_id); </code></pre> <p>Or I could use PHP to determine empty <code>property_value</code> sets and build a second query. So I would need this:</p> <pre><code>DELETE FROM asset_property WHERE 'PRIMARY KEY' IN ('146-3'); </code></pre> <p>The syntax is okay, but 0 rows are affected.</p> <p>I've tried this:</p> <pre><code>SELECT 'PRIMARY KEY' FROM asset_property WHERE asset_id = 146; </code></pre> <p>But the result is:</p> <pre><code>| PRIMARY KEY | |:------------| | PRIMARY KEY | | PRIMARY KEY | </code></pre> <p>The <a href="http://dev.mysql.com/doc/refman/4.1/en/multiple-column-indexes.html" rel="nofollow">MySQL Manual</a> seams to say you can't.</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.
 

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