Using BETWEEN condition
BETWEEN condition is used to retrieve records with in the given range.
The syntax of BETWEEN condition:
SELECT column_name(s) FROM table_name Where column_name BETWEEN value1 AND value2;
Using BETWEEN condition
BETWEEN condition is used to retrieve records with in the given range.
The syntax of BETWEEN condition:
SELECT column_name(s) FROM table_name Where column_name BETWEEN value1 AND value2;
The IN function can be used to replace the OR condition. It is also used to specify multiple value together with the WHERE clause.
The syntax of IN function:
SELECT column_name(s) FROM table_name Where column_name IN (value1,value2,etc…);
Using HAVING clause
HAVING clause is somewhat similar to WHERE clause and it is used together with the GROUP BY clause. It was added to SQL to combine with the aggregate functions because the WHERE clause doesn’t allow aggregates.
The syntax of HAVING clause:
SELECT column_name, aggregate_function(column_name) FROM table_name GROUP BY column_name HAVING aggregate_function(column_name) operator value;
DELETE statement
In this lesson we are going to write a PHP script that deletes records in MySQL database using the DELETE statement.
We can execute any sql query like insert, update, delete, select etc. using the mysql_query() function.
In this lesson we need to three pages namely the list.php, deleteform.php and deleteprocess.phpHere is the code(list.php):
UPDATE statement
In this lesson we are going to write a PHP script that updates records in MySQL database using the UPDATE statement.
Parameter of UPDATE command:
We can execute any sql query like insert, update, delete, select etc. using the mysql_query() function.
The ORDER BY Clause
In this lesson we are going to write PHP scripts that select a records in MySQL and sort it using the ORDER BY clause.
Using ORDER BY clause we can sort the data in a recordset in a ascending or descending order.
ASC – ascending order (default)
DESC – descending order
We can execute any sql query like insert, update, delete, select etc. using the mysql_query() function.Here is the code:
The Where Clause
In this lesson we are going to write PHP scripts that select a specific records in MySQL using the WHERE clause
Using WHERE clause we can specify a selection criteria to select, update,delete required records from a table.
We can execute any sql query like insert, update, delete, select etc. using the mysql_query() function.Here is the code: name it as php_where.php
PHP-MySQL Lesson: Select Data in Database and Display the record in HTML table
In this lesson we are going to write PHP scripts that select records in MySQL database and display it in HTML table.
The SELECT statement in sql is used to select a record in the database. In PHP, mysql_query() function is used to execute SELECT query.Here is the code: save it as php_select.php
Insert records
In this lesson we are going to write a PHP script that inserts a new record in our database through HTML forms.
The INSERT INTO statement in sql is used to insert a record in the database. In PHP, mysql_query() function is used to execute INSERT INTO query. We can execute any sql query like insert, update, delete, select etc. using the mysql_query() function.
We need two pages here namely the insert.php and the insertform.php or insertform.html.On our insertform.html we are going to create a form to collect the data entered by the user.
Column Aliases
To rename a column in database table, use the AS keyword it allows you to alias the name to different value.
The syntax of AS keyword:
SELECT column_name(s)AS alias_name FROM table_name
AS keyword example:
SELECT f_name AS Firstname FROM employee_record;