Basic SQL commands
- SQL query using a pattern:
Select * from '[table name]' where [field name] like '[text]%'
The '%' sign is a wildcard; eg: Eliz%
- SQL query using exact words:
Select * from '[table name]' where [field name] = '[text]'
Eg: 'Elizabeth Smith'
- SQL query using pattern and 2 wildcards:
Select * from '[table name]' where [field name] = '[text]%[text]%'
Eg: 'Eliz%Sm%'
- SQL query using multiple exact words:
Select * from '[table name]' where [field name] ='[search text]' or [field name] = '[search text]'
EG: zip='10001' or zip='10002'
- This SQL command changes a field or fields in a table based on a pattern matching another field. The basic command is an UPDATE:
UPDATE [table]
SET [field1]='[new data]',
[field2]='[new data]'
WHERE [any field in database] = '[data]'
An example:
UPDATE representativetable
SET title='Assemblyman',
name='Rafael Espinal',
WHERE district = 'A054'
The above command looks for district A054 and changes the title and name fields.