Articles on Trending Technologies

Technical articles with clear explanations and examples

How to query between two dates in MySQL?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 18K+ Views

You can query between dates with the help of BETWEEN statement. The syntax is as follows −select *from yourTableName where yourColumnName between ‘yourStartingDate’ and curdate().Use curdate() or now(), both these functions will work. To understand the above syntax, let us create a table −mysql> create table BetweenDateDemo −> ( −> StartDate datetime −> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table with the help of the following query −mysql> insert into BetweenDateDemo values(date_add(now(), interval -1 year)); Query OK, 1 row affected (0.11 sec) mysql> insert ...

Read More

Remove trailing zeros in decimal value with changing length in MySQL?

George John
George John
Updated on 30-Jul-2019 12K+ Views

You can remove trailing zeros using TRIM() function. The syntax is as follows.SELECT TRIM(yourColumnName)+0 FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table removeTrailingZeroInDecimal    -> (    -> Id int not null auto_increment,    -> Amount decimal(5, 2),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (1.01 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into removeTrailingZeroInDecimal(Amount) values(405.50); Query OK, 1 row affected (0.22 sec) mysql> insert into removeTrailingZeroInDecimal(Amount) values(23.05); Query OK, ...

Read More

How to return the nth record from MySQL query?

Jennifer Nicholas
Jennifer Nicholas
Updated on 30-Jul-2019 1K+ Views

To get the nth record from MySQL query, you can use LIMIT. The syntax is as follows −select *from yourTableName order by yourColumnName limit n, 1;To understand the above syntax, let us create a table. The following is the query to create a table −mysql> create table NthRecordDemo −> ( −> Id int, −> Name varchar(200) −> ); Query OK, 0 rows affected (0.92 sec)Insert some records in the table using the following query −mysql> insert into NthRecordDemo values(100, 'John'); Query OK, 1 row affected (0.09 sec) ...

Read More

Empty string in not-null column in MySQL?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 3K+ Views

In PHP, the empty string equals to a NULL value, but in MySQL, the case is the different i.e. empty string is not equal to NULL value. To understand the above syntax, let us create a column with NOT NULL constraint while you can insert an empty string.Let us create a table. The query to create a table is as follows −mysql> create table EmptyStringNotNullDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(10) not null,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.83 sec)Now you can insert some records ...

Read More

How do you OR two MySQL LIKE statements?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 291 Views

You can OR two like statements using the following syntax −SELECT *FROM yourTableName WHERE (yourColumnName like '%yourValue1%' OR yourColumnNamelike '%yourValue2%') AND yourColumnName = yourValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ORLikeDemo    -> (    -> Id int not null auto_increment,    -> FirstName varchar(15),    -> LastName varchar(15),    -> Primary Key(Id)    -> ); Query OK, 0 rows affected (1.19 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into ORLikeDemo(FirstName, LastName) values('John', 'Smith'); Query OK, ...

Read More

What are the latest electronic home decor devices used these days?

Ridhi Arora
Ridhi Arora
Updated on 30-Jul-2019 397 Views

Home is where the heart is! And one feels like calling a house as a home if the home is well decorated or is made attractive using flowers or fragrances that please the senses. But, gone are the days when only flowers or bonsai plants could decorate home. The latest trend is the use of electronic devices for home decor.Some of them areClocks: Clocks were used earlier just to note the time. But, these have actually become a luxury symbol now. Not only the brand makes it look costly, but also the design. The other day, I went to a ...

Read More

Improve MySQL Search Performance with wildcards (%%)?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 538 Views

No, MySQL won’t improve search performance whenever you have leading wildcards because MySQL will be unable to use the index. If you change to ‘anyLetter%’ then it will be able to use indexThe below syntax is better to use with trailing wildcards. The syntax is as follows −SELECT *FROM yourTableName WHERE yoorColumnName LIKE ‘anyLetter%’;The query to create a table is as follows −mysql> create table TrailingWildCardDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name Varchar(20), -> PRIMARY KEY(Id) -> ); Query OK, 0 ...

Read More

What is the difference between a simile and a metaphor?

Ridhi Arora
Ridhi Arora
Updated on 30-Jul-2019 790 Views

Poems are different and similar in the manner and matter they possess. The manner in which a poet expresses his ideas deal with literary devices such as simile, metaphor, hyperbole, contrast, repetition, imagery etc. Both simile and metaphor are used as comparative literary devices.Comparison Between Simile and MetaphorSimile - Similes are used to compare attributes of two objects or persons using words like or as. It must be noted that use of like or as always does not imply the presence of a simile. What is important is a direct comparison taking place.For Example,  Her cheeks are red as a rose.In ...

Read More

How to perform Increment in MySQL Update?

Vrundesha Joshi
Vrundesha Joshi
Updated on 30-Jul-2019 1K+ Views

To update values incrementally in MySQL, you need to create a variable with the help of SET command. The syntax to create a variable is as follows −set @anyVariableName := 0;To update value, you need to use UPDATE command. Let us begin with creating a table. The query to create a table −mysql> create table UpdateValueIncrementally −> ( −> ProductId int −> ); Query OK, 0 rows affected (0.90 sec)Insert records in the table with the help of select statement. The query is as follows −mysql> insert into UpdateValueIncrementally values(10); Query ...

Read More

How to alter the database engine of a MySQL database table?

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 551 Views

First, determine the type of MySQL database i.e. whether its engine is InnoDB or MyISAM. To achieve this, use engine column from the information_schema.columns.tables.The syntax is as follows.SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ’yourDatabaseName’ AND TABLE_NAME = ’yourTableName’;Here, I have a table with the name ‘StudentInformations’ −mysql> create table StudentInformations    -> (    -> StudentId int not null auto_increment,    -> StudentFirstName varchar(20),    -> StudentLastName varchar(20),    -> Primary Key(StudentId)    -> ); Query OK, 0 rows affected (0.57 sec)Now you can know the table is using InnoDB or MyISAM using the implementation of above syntax. Our ...

Read More
Showing 60311–60320 of 61,299 articles
Advertisements