INTRODUCTION TO DATABASE Contd.
Hello All...
welcome every one. I'm going to start PHP lectures for Very Beginners, who
wants to learn PHP from very beginning. No matter if you do not have any basic
programming concept. If you follow my tutorials I hope you will surely get some
how good knowledge of PHP.
Today our
Topic is
DATABASE
From the previous lecture you learnt how to display all records and also
particular columns from a table. Now today we are going to make an increment in
`SELECT` statement, if we want to display a single record from a column not the
whole column, just small increment in `SELECT` query. Include `WHERE`
condition, just like this:
Here is the syntax:
SELECT (requirement) => FROM (table) => WHERE (condition)
SELECT * FROM user
WHERE id = 5;
It will display all the records whose id is 5. Instead of `id` you can
write any column name within a table.
E.g. SELECT * FROM students
WHERE name = “John”;
It will display all the records whose name is “John”.
ð Selecting all teachers whose salary is greater than 15000:
SELECT * FROM teachers
WHERE salary >= 15000;
ð Select all the records from employees who work at night shift and salary
is 10000:
SELECT * FROM employees
WHERE shift = “night” AND salary = 15000;
ð Selecting all employees whose salary is between 15000-20000:
SELECT * FROM employees
WHERE salary BETWEEN 15000 AND 20000
ð Selecting all the teachers who teaches either IT, SW or CS:
SELECT * FROM teachers
WHERE subject IN(IT, SW, CS);
ð Selecting all the employees whose name starts with `A`:
SELECT * FROM employees
WHERE name LIKE “A%”;
`A%` shows that first letter should start with A after that any other
letter. Similarly you can search all records whose name ends with `A`. just
make small change in `Where` statement
WHERE name LIKE “%A”;
These were main and important queries used with SELECT statement. I hope
you all got the concept. Further you must practice yourself. In coming lecture
we will be learning about `Database Constraints`.
Thanks Guys.
Any thing missing or any question from this topic you can comment below, I will
be trying to solve and answer your question.
Our topic
continues to `Database`
Good Luck J
No comments:
Post a Comment