George John has Published 1167 Articles

mysql_fetch_array vs mysql_fetch_assoc vs mysql_fetch_object?

George John

George John

Updated on 30-Jul-2019 22:30:23

2K+ Views

These mysql_* functions are deprecated and other functions are available that gives better security and functionality. Note: As an alternative, use either _assoc or _row though. mysql_fetch_assoc The function returns an associative array of strings that corresponds to the fetched row, or FALSE if there are no more rows. The ... Read More

How to take backup of a single table in a MySQL database?

George John

George John

Updated on 30-Jul-2019 22:30:23

541 Views

The backup of a table can be made with the help of backup table as well as mysqldump utility. The backup table concept was used in MySQL version 5.0 and its earlier version. Here, I am performing backup with the help of mysqldump. Firstly, we will open cmd with the ... Read More

Passing an array to a query using WHERE clause in MySQL?

George John

George John

Updated on 30-Jul-2019 22:30:23

7K+ Views

We can pass an array with the help of where IN clause. Let us first create a new table for our example. mysql> create table PassingAnArrayDemo   -> (   -> id int,   -> Firstname varchar(100)   -> ); Query OK, 0 rows affected (1.60 sec) Let ... Read More

WHERE vs HAVING in MySQL?

George John

George John

Updated on 30-Jul-2019 22:30:23

162 Views

We can use a conditional clause called the WHERE Clause to filter out the results. Using this WHERE clause, we can specify a selection criteria to select the required records from a table. The HAVING clause specify filter conditions for a group of rows or aggregates WHERE clause cannot be used ... Read More

How to create a temporary MySQL table in a SELECT statement without a separate CREATE TABLE?

George John

George John

Updated on 30-Jul-2019 22:30:23

3K+ Views

To create a temporary table in a SELECT statement we use TEMPORARY keyword. This temporary table will be visible for the current session and whenever a session is closed, it is automatically destroyed. Two sessions can use the same temporary table. Creating a table. mysql> create table MyTableDemo   -> ... Read More

How do I check to see if a value is an integer in MySQL?

George John

George John

Updated on 30-Jul-2019 22:30:23

11K+ Views

To check if the given value is a string or not ,we use the cast() function. If the value is not numeric then it returns 0, otherwise it will return the numeric value. In this way, we can check whether the value is an integer or not. Case 1 − ... Read More

How to subtract 10 days from the current datetime in MySQL?

George John

George John

Updated on 30-Jul-2019 22:30:23

2K+ Views

Firstly, let us get the current datetime with the help of the now() function. mysql> select now(); The following is the output. +---------------------+ | now()               | +---------------------+ | 2018-11-01 19:55:56 | +---------------------+ 1 row in set (0.00 sec) Syntax to subtract 10 days with the help ... Read More

How to change MySQL timezone?

George John

George John

Updated on 30-Jul-2019 22:30:23

311 Views

To change the timezone in MySQL, we can use the SET command. The following is the syntax. SET time_zone=’someValue’; Let us now use the above syntax and apply it in the below query. mysql > SET time_zone = '+8:00'; Query OK, 0 rows affected (0.00 sec) ... Read More

Get the new record key ID from MySQL insert query?

George John

George John

Updated on 30-Jul-2019 22:30:23

473 Views

We can get new record key with the help of LAST_INSERT_ID() function from MySQL. First, we will create a table and for inserting record, we will use LAST_INSERT_ID(). Let us create a table with the help of create command. The query is as follows − mysql> create table LastInsertRecordIdDemo ... Read More

Usage of backtick in SQL statements?

George John

George John

Updated on 30-Jul-2019 22:30:23

380 Views

The backtick can be used in MySQL. To create a table, we can put table_name in backticks. Example of Backtick in MySQL. The CREATE command is used to create a table. Here, we have added the table name using the backtick symbol. mysql> create table `backtickSymbol` ... Read More

Advertisements