Karthikeya Boyini has Published 2383 Articles

How to select everything before @ in an email-id with in MySQL?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jun-2020 12:25:33

590 Views

Use SUBSTRING_INDEX to select everything before @ in an email-id −select substring_index(yourColumnName, '@', 1) from yourTableName;Let us first create a table −mysql> create table DemoTable -> ( -> EmployeeMailId varchar(100) -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

How to add current date to an existing MySQL table?

karthikeya Boyini

karthikeya Boyini

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

291 Views

To update an existing table, use UPDATE. With that, to set the current date, use the CURDATE() method −update yourTableName set yourCoumnName=CURDATE();Let us first create a table −mysql> create table DemoTable -> ( -> DueDate datetime -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table ... Read More

How to get row count of two tables in different databases in a single query?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jun-2020 12:21:37

329 Views

For this, you can use aggregate function COUNT(*). Let us first create a table in let’s say database “web” −mysql> create table DemoTable1    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert ... Read More

How to insert auto_increment in an already created table in MySQL?

karthikeya Boyini

karthikeya Boyini

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

178 Views

Use ALTER command for this. Let us first create a table −mysql> create table DemoTable -> ( -> StudentName varchar(100) -> ); Query OK, 0 rows affected (0.46 sec)Here is the query to insert auto_increment −mysql> alter table DemoTable ADD COLUMN StudentId int NOT NULL; Query OK, 0 rows affected ... Read More

Finding number of occurrences of a specific string in MySQL?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jun-2020 12:02:21

372 Views

Use LENGTH() for this. Let us first create a table −mysql> create table DemoTable -> ( -> Value text -> ); Query OK, 0 rows affected (0.74 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('10, 20, 10, 30, 10, 40, 50, 40'); Query OK, ... Read More

How do I see what a MySQL view is made of?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jun-2020 11:54:49

106 Views

Following is the syntax −show create view yourViewName;Let us first create a table −mysql> create table DemoTable -> ( -> StudentName varchar(20) -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.14 ... Read More

Get the difference between dates and calculate salary with MySQL?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jun-2020 11:33:42

302 Views

Let’s say you need to get the difference between dates (JoiningDate – EndDate) of a month i.e. days to calculate the salary. The daily-wage salary is let’s say 300; therefore for 20 days, it will 6000. In the same way, for 27 days, it will be 8100.For our example, let ... Read More

Select multiple columns and display in a single column in MySQL?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jun-2020 11:30:41

5K+ Views

Use concat() for this. Let us first create a table −mysql> create table DemoTable    -> (    -> FirstName varchar(30),    -> LastName varchar(30)    -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'Brown'); Query ... Read More

Add a new column and set values in it on the basis of conditions in MySQL?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jun-2020 11:29:33

3K+ Views

To set values on the basis of conditions, use IF() method. Let us first create a table −mysql> create table DemoTable    -> (    -> Age int    -> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable ... Read More

How to order by timestamp in MySQL?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jun-2020 11:28:26

705 Views

To order by timestamp, use the ORDER BY as in the following syntax −select *from yourTableName ORDER BY STR_TO_DATE(`yourColumnName`, '%m/%d/%Y%h:%i:%s %p');Let us first create a table −mysql> create table DemoTable    -> (    -> `timestamp` varchar(100)    -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in ... Read More

Advertisements