Ankith Reddy has Published 996 Articles

Combine INSERT, VALUES, and SELECT in MySQL

Ankith Reddy

Ankith Reddy

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

1K+ Views

You can combine the insert, values and select statement using below syntaxinsert into yourFirstTableName(yourColumnName1, yourColumnName2, .......N) select yourColumnName1, yourColumnName2, .......N from yourSecondTableName where yourCondition;To understand the above syntax, let us create two tables in which first table will get the record from the second table.Let us create the first table ... Read More

How to find all uppercase strings in a MySQL table?

Ankith Reddy

Ankith Reddy

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

1K+ Views

To find all upper case strings in a MySQL table, you need to use BINARY UPPER() function. The syntax is as follows:SELECT *FROM yourTableName WHERE yourColumnName=BINARY UPPER(yourColumnName);To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table FindUpperCaseDemo    -> ... Read More

Limit length of longtext field in MySQL SELECT results?

Ankith Reddy

Ankith Reddy

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

1K+ Views

You can use SUBSTRING() from MySQL to limit length of strings. The syntax is as followsSELECT SUBSTRING(yourColumnName, 1, yourIntegerValueToGetTheCharacters) as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table limitLengthOfLongTextDemo -> ( ... Read More

Set MySQL DECIMAL with accuracy of 10 digits after the comma?

Ankith Reddy

Ankith Reddy

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

465 Views

As you know the DECIMAL() method takes two parameter. The first parameter tells about the total number of digits and second parameter tells about number of digits after decimal point. Therefore, if you use DECIMAL(10, 10) that means you can use only 10 fractional digit.For Example: Store 0.9999999999 with DECIMAL(20, ... Read More

What is the equivalent of MySQL TIME_TO_SEC() method in PHP to convert datetime to seconds?

Ankith Reddy

Ankith Reddy

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

1K+ Views

The function TIME_TO_SEC() can be used in MySQL. If you want to convert datetime to seconds use the strtotime() from PHP. The MySQL syntax is as follows:SELECT TIME_TO_SEC(ABS(timediff(‘yourDateTimeValue’, now())));Now you can convert PHP datetime to seconds with the help of strtotime().First, you need to install XAMPP server to run your ... Read More

How to select yesterday's date in MySQL?

Ankith Reddy

Ankith Reddy

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

648 Views

To select yesterday’s date, use the subdate() function from MySQL. The syntax is as followsselect subdate(yourDatetimeColumnName) as anyVariableName from yourTableName;To understand the above syntax, let us create a tablemysql> create table YesterdayDateDemo -> ( -> VisitedDateTime datetime -> ); Query OK, 0 rows affected (0.59 sec)Let us now insert date ... Read More

Find rows where column value ends with a specific substring in MySQL?

Ankith Reddy

Ankith Reddy

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

2K+ Views

To find rows and update with new value where column value ends with specific substring you need to use LIKE operator.The syntax is as follows:UPDATE yourTableName SET yourColumnName=’yourValue’ WHERE yourColumnName LIKE ‘%.yourString’;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> ... Read More

Generate the row count (serial number) of records after returning the result in MySQL query?

Ankith Reddy

Ankith Reddy

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

5K+ Views

To generate serial number i.e. row count in MySQL query, use the following syntax.SELECT @yourVariableName − = @yourVariableName+1 anyAliasName,    yourColumnName1, yourColumnName2, yourColumnName3, ....N from yourTableName ,    (select @yourVariableName − = 0) as yourVariableName;To understand the above syntax, let us create a table. The query to create a table ... Read More

Need help selecting non-empty column values from MySQL?

Ankith Reddy

Ankith Reddy

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

6K+ Views

Select non-empty column values using NOT IS NULL and TRIM() function. The syntax is as follows.SELECT * FROM yourTableName WHERE yourColumnName IS NOT NULL AND TRIM(yourColumnName) ' ';You can select non-empty value as well as whitespace from column using the same TRIM() function.To understand the syntax we discussed above, ... Read More

How can we use nested transactions in MySQL?

Ankith Reddy

Ankith Reddy

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

2K+ Views

We can work with nested transactions in MySQL with the help of SAVEPOINT.Firstly, create a table. After that, begin the transaction.Now, insert records in the table created above. Use SAVEPOINT statement to set a named transaction savepoint with a name of identifier.Here are all the steps shown in the form ... Read More

Advertisements