Arjun Thakur has Published 1109 Articles

How to list databases vertically in MySQL command line?

Arjun Thakur

Arjun Thakur

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

158 Views

You can use backward slash followed by G i.e. \G instead of semicolon(;). The syntax is as follows to display database names vertically in MySQL command lineSHOW DATABASES \GTo display all database names vertically, you need to use \G. The query is as followsmysql> show databases\GThe following is the output*************************** ... Read More

How to add column values in MySQL without using aggregate function?

Arjun Thakur

Arjun Thakur

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

325 Views

You can add column values without using aggregate function like sum(). For that, the syntax is as follows −SELECT *, (yourColumnName1+yourColumnName2+yourColumnName3, ....N) as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table AddingColumnDemo    -> ... Read More

SELECT MySQL rows where today's date is between two DATE columns?

Arjun Thakur

Arjun Thakur

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

997 Views

To select MySQL rows where today’s date is between two date columns, you need to use AND operator. The syntax is as follows:SELECT *FROM yourTableName WHERE yourDateColumnName1 = ‘’yourDateValue’;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table selectDates ... Read More

Solve ERROR 1396 (HY000): Operation DROP USER failed for 'user'@'localhost' in MySql?

Arjun Thakur

Arjun Thakur

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

2K+ Views

This error occurs when you drop a user with localhost while you have created a user with ‘%’.Let us create a user with ‘%’ and drop the user as a localhost. The syntax is as followsCREATE USER 'yourUserName'@'%' IDENTIFIED BY 'yourPassword';Let us create a user using the above syntax. The ... Read More

Fix for MySQL ERROR 1406: Data too long for column” but it shouldn't be?

Arjun Thakur

Arjun Thakur

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

5K+ Views

This error can occur if you try to set data higher than the allowed limit. As an example, you cannot store a string in a column of type bit because varchar or string takes size higher than bit data type.You need to use the following syntax for bit type column:anyBitColumnName= ... Read More

Changing year in MySQL date?

Arjun Thakur

Arjun Thakur

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

3K+ Views

To change the year in MySQL date, you need to use DATE_FORMAT() function with UPDATE command. The syntax is as follows.UPDATE yourTableName SET yourDateColumnName = DATE_FORMAT(yourDateColumnName ,'yourYearValue-%m-%d');To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ChangeYear   ... Read More

How to Order by date in MySQL but place empty dates in the end?

Arjun Thakur

Arjun Thakur

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

412 Views

Order by date and set the empty dates in the last with the help of ORDER BY clause and IS NULL property. The syntax is as follows:SELECT *FROM yourTableName ORDER BY (yourDateColumnName IS NULL), yourDateColumnName DESC;In the above syntax, we will sort the NULL first after that date. To understand ... Read More

What is the data type for unix_timestamp in MySQL?

Arjun Thakur

Arjun Thakur

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

1K+ Views

The best data type for unix_timestamp in MySQL is integer. The integer data type is as followsint(11);The integer data type is useful for condition checking like ( > , create table UnixTime -> ( -> DueTime datetime -> ); Query OK, ... Read More

Sorting a VARCHAR column as FLOAT using the CAST operator isn’t working in MySQL ?

Arjun Thakur

Arjun Thakur

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

946 Views

If your cast does not work, then you can use yourColumnName*1 with ORDER BY clause.Using yourColumnName*1. The syntax is as follows:SELECT yourColumnName1, yourColumnName2, ...N FROM yourTableName ORDER BY yourColumnName*1 DESC;You can also use CAST() operator. The syntax is as follows:SELECT yourColumnName1, yourColumnName2, ...N FROM yourTableName ORDER BY CAST(yourColumnName as DECIMAL(8, ... Read More

Data Classes in Python (dataclasses)

Arjun Thakur

Arjun Thakur

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

573 Views

The dataclasses is a new module added in Python's standard library since version 3.7. It defines @dataclass decorator that automatically generates constructor magic method __init__(), string representation method __repr__(), the __eq__() method which overloads == operator (and a few more) for a user defined class.The dataclass decorator has following signaturedataclass(init=True, ... Read More

Advertisements