Rama Giri has Published 110 Articles

MySQL query to search within the last 5 characters in a column?

Rama Giri

Rama Giri

Updated on 30-Jun-2020 12:57:19

142 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> EmployeeName varchar(100)    -> ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam Smith'); Query OK, 1 row affected (0.12 sec) mysql> ... Read More

How to select the sum of the column values with higher value in reach row with MySQL?

Rama Giri

Rama Giri

Updated on 30-Jun-2020 12:51:01

90 Views

Use the CASE statements and set conditions for the same. Let us first create a table −mysql> create table DemoTable    -> (    -> X int,    -> Y int    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> ... Read More

MySQL query to fetch records wherein timestamp is before 15+ days?

Rama Giri

Rama Giri

Updated on 30-Jun-2020 12:49:39

193 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> ArrivalDate datetime    -> ); Query OK, 0 rows affected (0.91 sec)Insert some records in the table using insert command. Let’s say the current date is 2019-07-03 −mysql> insert into DemoTable values('2019-07-03'); Query OK, 1 ... Read More

How do I multiply an unsigned int by -1 on a MySQL SELECT?

Rama Giri

Rama Giri

Updated on 30-Jun-2020 12:47:59

84 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.17 sec) mysql> insert ... Read More

How to concatenate MySQL distinct query results into a string?

Rama Giri

Rama Giri

Updated on 30-Jun-2020 12:45:56

1K+ Views

Use group_concat() function from MySQL to concatenate. Let us first create a table −mysql> create table DemoTable    -> (    -> Subject varchar(10)    -> ); Query OK, 0 rows affected (0.43 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('C'); Query OK, 1 ... Read More

Can we use ADD and CHANGE with ALTER Statement in MySQL?

Rama Giri

Rama Giri

Updated on 30-Jun-2020 12:41:40

71 Views

Yes, we can use ADD and CHANGE with ALTER statement. Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(100),    -> Age int    -> ); Query OK, 0 rows affected (0.84 sec)Now check the description of table.mysql> desc DemoTable;OutputThis will produce ... Read More

How to prevent duplicate INSERT in MySQL?

Rama Giri

Rama Giri

Updated on 30-Jun-2020 12:30:50

11K+ Views

For this, you can use UNIQUE INDEX −alter table yourTableName ADD UNIQUE INDEX(yourColumnName1, yourColumnName2, ....N);Let us first create a table −mysql> create table DemoTable    -> (    -> Value1 int,    -> Value2 int    -> ); Query OK, 0 rows affected (0.55 sec)Following is the query to add ... Read More

Set the seconds for a specified date according to universal time.

Rama Giri

Rama Giri

Updated on 23-Jun-2020 08:08:31

77 Views

JavaScript date setUTCSeconds() method sets the seconds for a specified date according to universal time.The following are the parameters for setUTCSeconds(secondsValue[, msValue]) methodLsecondsValue − An integer between 0 and 59, representing the seconds.msValue − A number between 0 and 999, representing the milliseconds.ExampleYou can try to run the following code ... Read More

Where MySQL views can be inconsistent and how can we ensure their consistency?

Rama Giri

Rama Giri

Updated on 22-Jun-2020 13:50:38

98 Views

In case of updateable views, it is quite possible that we update the data that is not visible through the view because we create a view to revealing only the partial data of a table. Such kind of updates makes the view inconsistent. We can ensure the consistency of views ... Read More

How can we get the count of all MySQL event-related operations collectively?

Rama Giri

Rama Giri

Updated on 22-Jun-2020 12:46:43

90 Views

With the help of SHOW STATUS statement, we can get the count of MySQL event-related operations. It can be used as follows −mysql> SHOW STATUS LIKE '%event%'; +--------------------------+-------+ | Variable_name            | Value | +--------------------------+-------+ | Com_alter_event          | 16    | | ... Read More

Advertisements