Rama Giri has Published 110 Articles

How to get the creation time of recently created table in MySQL?

Rama Giri

Rama Giri

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

143 Views

Following is the syntax −select table_name, create_time from information_schema.TABLES where table_schema = 'yourDataBaseName' order by CREATE_TIME desc limit 1;Let us create the first table (Time: 2019-06-10 16:40:51) −mysql> create table DemoTable1    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(100),    -> StudentAge ... Read More

Can we replace a number with a String in a MySQL result set?

Rama Giri

Rama Giri

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

326 Views

Yes, we can do that using the CASE statement. Let us first create a table −mysql> create table DemoTable    -> (    -> isMarried boolean    -> ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(true); Query ... Read More

Is there PHP basename() equivalent in MySQL?

Rama Giri

Rama Giri

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

100 Views

If given a string containing a path to a file, the PHP basename() function will return the base name of the file. To get its equivalent in MySQL, you can use SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable    -> (    -> Location varchar(200)   ... Read More

Concatenating two strings in MySQL with space?

Rama Giri

Rama Giri

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

894 Views

For this, you can use concat() function from MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20),    -> Subject varchar(100)    -> ); Query OK, 0 rows affected (17.73 sec)Insert some ... Read More

How to return rows that have the same column values in MySQL?

Rama Giri

Rama Giri

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

170 Views

Use GROUP BY clause for this. Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int,    -> StudentMarks int    -> ); Query OK, 0 rows affected (4.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(23, ... Read More

MySQL query to get only the minutes from datetime?

Rama Giri

Rama Giri

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

190 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> ShippingDate datetime    -> ); Query OK,  0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-10 10:04:45'); Query OK,  1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-06-11 05:45:00'); Query OK,  1 row affected (0.23 sec) mysql> insert into DemoTable values('2019-06-12 07:00:55'); Query OK,  1 row affected (0.14 sec)Display all records from the table using select statement ... Read More

Concatenate date and time from separate columns into a single column in MySQL

Rama Giri

Rama Giri

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

198 Views

For this, concatenate both the date and time using CONCAT() function. Let us first create a table −mysql> create table DemoTable    -> (    -> ShippingDate date,    -> ShippingTime time,    -> ShippingDatetime datetime    -> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the ... Read More

Display all records ignoring the current date record in MySQL

Rama Giri

Rama Giri

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

76 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(100),    -> DueDate datetime    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command. Let’s say the current date is “2019-07-05” −mysql> insert into DemoTable ... Read More

Set numbers as a varchar field and compare in MySQL

Rama Giri

Rama Giri

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

83 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentScore varchar(100)    -> ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentScore) values('90'); Query ... Read More

MySQL query to replace a string after the last / in a column with directory links?

Rama Giri

Rama Giri

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

97 Views

For this, use the substring_index() method. Let us first create a table −mysql> create table DemoTable    -> (    -> FolderName varchar(100),    -> FolderLocation varchar(200)    -> ); Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('CProgram', ... Read More

Advertisements