Found 4378 Articles for MySQL

How can I generate days from the range of dates with the help of MySQL views?

karthikeya Boyini
Updated on 22-Jun-2020 14:11:56

228 Views

To illustrate it we are creating the following views −mysql> CREATE VIEW digits AS     -> SELECT 0 AS digit UNION ALL     -> SELECT 1 UNION ALL     -> SELECT 2 UNION ALL     -> SELECT 3 UNION ALL     -> SELECT 4 UNION ALL     -> SELECT 5 UNION ALL     -> SELECT 6 UNION ALL     -> SELECT 7 UNION ALL     -> SELECT 8 UNION ALL     -> SELECT 9; Query OK, 0 rows affected (0.08 sec) mysql> CREATE VIEW numbers AS SELECT ones.digit + ... Read More

How can we handle NULL values stored in a MySQL table by using PHP script?

Srinivas Gorla
Updated on 22-Jun-2020 14:09:52

286 Views

We can use the if...else condition in PHP script to prepare a query based on the NULL value. To illustrate it we are having the following example −ExampleIn this example, we are using the table named ‘tcount_tbl’ having the following data −mysql> SELECT * from tcount_tbl; +-----------------+----------------+ | tutorial_author | tutorial_count | +-----------------+----------------+ |      mahran     |       20       | |      mahnaz     |      NULL      | |       Jen       |      NULL      | |      Gill       |       20       | +-----------------+----------------+ 4 rows in set (0.00 sec)Now, the following is a PHP script that takes the value of ‘tutorial_count’ from outside and compares it with the value available in the field.

How to write PHP script by using MySQL JOINS inside it to join two MySQL tables?

mkotla
Updated on 22-Jun-2020 14:11:18

4K+ Views

We can use the syntax of MySQL JOIN for joining two tables into the PHP function – mysql_query(). This function is used to execute the SQL command and later another PHP function – mysql_fetch_array() can be used to fetch all the selected data.To illustrate it we are having the following example −ExampleIn this example, we are using two MySQL tables which have the following data −mysql> SELECT * FROM tcount_tbl; +-----------------+----------------+ | tutorial_author | tutorial_count | +-----------------+----------------+ | mahran          |      20        | | mahnaz          |     ... Read More

How to write PHP script by using ORDER BY clause inside it to sort the data of MySQL table?

Abhinanda Shri
Updated on 22-Jun-2020 14:18:23

181 Views

We can use the similar syntax of the ORDER BY clause into the PHP function – mysql_query(). This function is used to execute the SQL command and later another PHP function – mysql_fetch_array() can be used to fetch all the selected data.To illustrate it we are having the following example −ExampleIn this example, we are writing a PHP script that will return the result in descending order of the authors of the tutorial −

How to write PHP script by using LIKE clause inside it to match the data from MySQL table?

Giri Raju
Updated on 22-Jun-2020 14:17:26

283 Views

We can use the similar syntax of the WHERE...LIKE clause into the PHP function – mysql_query(). This function is used to execute the SQL command and later another PHP function – mysql_fetch_array() can be used to fetch all the selected data if the WHERE...LIKE clause is used along with the SELECT command.But if the WHERE...LIKE clause is being used with the DELETE or UPDATE command, then no further PHP function call is required.To illustrate it we are having the following example −ExampleIn this example, we are writing a PHP script that will return all the records from the table named ‘tutorial_tbl’ ... Read More

How can we create a MySQL view by selecting some range of values from a base table?

Kumar Varma
Updated on 22-Jun-2020 14:00:50

117 Views

As we know that MySQL BETWEEN operator can be used to select values from some range of values. We can use BETWEEN operator along with views to select some range of values from the base table. To understand this concept we are using the base table ‘student_info’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | Shimla     ... Read More

How can we create MySQL view by selecting data based on pattern matching from base table?

Arjun Thakur
Updated on 22-Jun-2020 14:19:38

99 Views

MySQL LIKE operator is used to select data based on pattern matching. Similarly, we can use LIKE operator with views to select particular data based on pattern matching from the base table. To understand this concept we are using the base table ‘student_info’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | Shimla     | Computers  | | 130  | ... Read More

How can we create a MySQL view with GROUP BY clause?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:21

2K+ Views

We can use GROUP BY to group values from a column, and, if we want, we can perform calculations on that column. You can use COUNT, SUM, AVG, etc., functions on the grouped column. To understand GROUP BY clause with views we are creating a view named ‘Info’ using the base table ‘Student_info’ having the following data − mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History ... Read More

How to write PHP script to delete data from an existing MySQL table?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

233 Views

We can use the SQL DELETE command with or without the WHERE CLAUSE into the PHP function – mysql_query(). This function will execute the SQL command in a similar way it is executed at the mysql> prompt. To illustrate it we are having the following example − Example In this example, we are writing a PHP script to delete a record from MySQL table named ‘tutorial_tbl’ whose tutorial_id as 3.

How to write PHP script to update an existing MySQL table?

Sreemaha
Updated on 22-Jun-2020 14:01:31

217 Views

We can use the SQL UPDATE command with or without the WHERE CLAUSE in the PHP function – mysql_query(). This function will execute the SQL command in a similar way it is executed at the mysql> prompt. To illustrate it we are having the following example −ExampleIn this example, we are writing a PHP script to update the field named tutorial_title for a record having turorial_id as 3.

Advertisements