2,187
edits
m (→Data Types: Added "Numbers") |
m (→Insert / Update Rows: Added "INSERT ... SELECT") |
||
Line 74: | Line 74: | ||
== Insert / Update Rows == | == Insert / Update Rows == | ||
'''Basic Examples''' | |||
<source lang="mysql">INSERT INTO hosts (name, ping_ok) VALUES ('ServerA', 1) ON DUPLICATE KEY UPDATE ping_ok=1; | <source lang="mysql">INSERT INTO hosts (name, ping_ok) VALUES ('ServerA', 1) ON DUPLICATE KEY UPDATE ping_ok=1; | ||
UPDATE hosts SET ping_ok=0, reason='Time Out' WHERE name='ServerA'; </source> | UPDATE hosts SET ping_ok=0, reason='Time Out' WHERE name='ServerA'; </source> | ||
<br>'''INSERT ... SELECT'''<br> | |||
Used when you want you want include data from another table in an <code>INSERT</code> statement (eg you want to reference a unique ID in another table) | |||
<source lang="mysql">INSERT INTO table (id, make, model) SELECT id, 'DELL', 'PE1950' FROM hosts WHERE ip=INET_ATON('159.104.7.171');</source> | |||
== Software Packages == | == Software Packages == |