Ankith Reddy has Published 1070 Articles

Limit length of longtext field in MySQL SELECT results?

Ankith Reddy

Ankith Reddy

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

977 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

316 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

873 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

504 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

1K+ 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

4K+ 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

5K+ 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

Python Low-level threading API

Ankith Reddy

Ankith Reddy

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

463 Views

The '_thread' module in Python library provides a low-level interface for working with light-weight processes having multiple threads sharing a global data space. For synchronization, simple locks (also called mutexes or binary semaphores) are defined in this module. The 'threading' built-in module provides a higher-level threading API built on top ... Read More

How to find the MySQL data directory from command line in Windows?

Ankith Reddy

Ankith Reddy

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

3K+ Views

To find the MySQL data directory, we can simply use the variable datadir. Let us see how to use the variable with select statement.The query is as follows −mysql> select @@datadir;Here is the output+---------------------------------------------+ | @@datadir ... Read More

Advertisements