Order Records and Delete N Rows in MySQL

AmitDiwan
Updated on 12-Dec-2019 07:35:13

175 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName) values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(FirstName) values('Adam'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(FirstName) values('John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(FirstName) values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(FirstName) values('Mike'); Query OK, 1 ... Read More

Change Current Directory Using Python

Rajendra Dharmkar
Updated on 12-Dec-2019 07:34:07

1K+ Views

You can change directory or cd in Python using the os module. It takes as input the relative/absolute path of the directory you want to switch to.For example>>> import os >>> os.chdir('my_folder')

Change Directory in Python

Rajendra Dharmkar
Updated on 12-Dec-2019 07:33:08

15K+ Views

You can change directory or cd in Python using the os module. It takes as input the relative/absolute path of the directory you want to switch to.For example>>> import os >>> os.chdir('my_folder')

Know Current Working Directory in Python

Rajendra Dharmkar
Updated on 12-Dec-2019 07:30:38

2K+ Views

To know the current working directory or pwd use the os module.For example>>> import os >>> print(os.getcwd()) /home/ayush/qna

Find Difference Between Two DateTime Values in MySQL

AmitDiwan
Updated on 12-Dec-2019 07:29:24

425 Views

To find the difference between two datetime values, you can use TIMESTAMPDIFF(). Let us first create a table −mysql> create table DemoTable    -> (    -> DueDatetime1 datetime,    -> DueDatetime2 datetime    -> ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-10-26 19:49:00', '2019-10-26 17:49:00'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-10-26 08:00:00', '2019-10-26 13:00:00'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-10-26 06:50:00', '2019-10-26 12:50:00'); Query OK, 1 row affected (0.68 sec)Display all records from the ... Read More

Add a Single Day to Datetime Field with MySQL Interval

AmitDiwan
Updated on 12-Dec-2019 07:27:21

174 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> DueDate date    ->); Query OK, 0 rows affected (2.11 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2018-12-31'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values('2018-12-30'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('2017-02-26'); Query OK, 1 row affected (0.47 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+------------+ ... Read More

Shift Row Values in MySQL to Change Existing ID Values

AmitDiwan
Updated on 12-Dec-2019 07:25:47

484 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20)    -> ); Query OK, 0 rows affected (1.07 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName) values('Chris'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(StudentName) values('Robert'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName) values('David'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(StudentName) values('Mike'); Query OK, 1 row affected (0.10 sec)Display all records from the table using select statement ... Read More

Delete Last Two Words from Every Column Value in MySQL

AmitDiwan
Updated on 12-Dec-2019 07:20:25

197 Views

For this, you can use the LEFT() function from MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(10)    -> ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------+ | ... Read More

Can We Use the Word 'User' for a MySQL Table?

AmitDiwan
Updated on 12-Dec-2019 07:17:57

348 Views

You cannot use “user” for a MySQL table because it is a reserved word in MySQL. You can change the name from user to users or something else or you can use backticks around the user word.The word user can be used to create a user or can select a user list from the MySQL database.Let us first create a table. Here, we have used the table name users −mysql> create table users    -> (    -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserName varchar(20),    -> UserAge int    -> ); Query OK, 0 rows ... Read More

MySQL Select Where Timestamp is in the Current Hour

AmitDiwan
Updated on 12-Dec-2019 07:15:06

252 Views

For this, you can use CURTIME(). Let us first create a table −mysql> create table DemoTable    -> (    -> ArrivalTime timestamp    -> ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-10-26 17:55:55'); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable values('2019-10-26 18:00:00'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-10-26 18:55:00'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2018-10-26 16:00:10'); Query OK, 1 row affected (0.20 sec)Display all records from the table using select ... Read More

Advertisements