beginner SQL conditional INSERT INTO question
Here's a pseudo-table:
Table: people
name : varchar
is_married : varchar
I have a php variable $selected_individual whose is_married status I need to update. I'm stuck after
SELECT * from people
WHERE name = '$selected_individual'
How do I update his is_married status?
This maybe related to this question but nested queries and JOIN开发者_运维问答 are way to advanced for me to get my head around at this point (I'll look into them after some much needed sleep).
edit: for example in this query,
INSERT INTO x_table(instance, user, item)
SELECT 919191, 123, 456
FROM dual
WHERE NOT EXISTS (SELECT * FROM x_table
WHERE user = 123
AND item = 456)
I can't seem to figure where can I plug in my 'yes' value myself for is_married column. (or where do I put VALUES ('yes') in there?)
update people set is_married = 'Y' where name = '$selected_individual';
While Paul Tomblin has provided a direct answer, I'd like to add the following recommendation and best practices:
- Read a General Introduction to SQL
- Use a primary key
- Prevent SQL Injection
精彩评论