MYSQL09: AND, Or and Not

We could include more than one condition in SELECT, UPDATE or DELETE statements.

students

id
name
age
marks
1
Calvin
12
56
2
Joe
15
45
3
Rosy
17
66

SELECT * FROM tableName WHERE field1 = value1 AND field2 = value2

this example retrieves records with condition where age more than 12 and marks more than 50.

SELECT * FROM students WHERE age > 13 AND marks > 50;

this will returns only one record that meet the condition.

Id
name
age
Marks
3
Rosy
17
66


to get records that’s either have age more than 16 or name is ‘Joe’, the SQL statement has OR logical comparison is as follows:

SELECT * FROM students WHERE age > 16 OR name = ‘Joe’;

Id
name
age
Marks
2
Joe
15
45
3
Rosy
17
66

to retrieve all records from students table, but not a records that has ‘Joe’ as name.

SELECT * FROM students WHERE NOT name = ‘Joe’;

Id
name
age
Marks
1
Calvin
12
56
3
Rosy
17
66

Comments

Popular posts from this blog

Drawing Simple Pie Chart

VB.net connecting to SQL Server

VB.net