Found 4219 Articles for MySQLi

Select current time with MySQL now() and convert it to GMT 0?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

389 Views

You can use utc_timestamp() for this. Following is the syntax −SELECT utc_timestamp();Let us check the current time using now().Following is the query −mysql> select now();This will produce the following output −+---------------------+ | now() | +---------------------+ | 2019-04-11 17:50:05 | +---------------------+ 1 row in set (0.00 sec)Following is the query to get GMT 0 −mysql> SELECT utc_timestamp();This will produce the following output −+---------------------+ | utc_timestamp()   | +---------------------+ | 2019-04-11 12:20:08 | +---------------------+ 1 row in set (0.00 sec)

How to convert all the records in a MySQL table from uppercase to lowercase?

Samual Sam
Updated on 30-Jul-2019 22:30:25

664 Views

Convert all the records in a MySQL table from uppercase to lowercase using UPDATE command along with LOWER() method.Let us first create a table −mysql> create table DemoTable    (    Id varchar(100),    StudentFirstName varchar(20),    StudentLastName varchar(20),    StudentCountryName varchar(10)    ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('STU-101', 'John', 'Smith', 'US'); Query OK, 1 row affected (0.59 sec) mysql> insert into DemoTable values('STU-102', 'John', 'Doe', 'UK'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('STU-103', 'David', 'Miller', 'AUS'); Query OK, 1 ... Read More

Display IDs in a particular order with MySQL IN()?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

155 Views

To display IDs in a particular order i.e. the order of your choice use FIELD() method.Let us first create a table −mysql> create table DemoTable    (    UserId int    ); Query OK, 0 rows affected (0.64 sec)Following is the query to insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(80); Query OK, 1 row affected (0.13 sec) ... Read More

Add a temporary column in MySQL where the values depend on another column?

Samual Sam
Updated on 30-Jul-2019 22:30:25

1K+ Views

You can use CASE statement for this and set conditions to get result in the temporary column.Let us first create a table −mysql> create table DemoTable    (    EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    EmployeeName varchar(20),    EmployeeSalary int,    EmployeeExperience int    ); Query OK, 0 rows affected (0.64 sec)Following is the query to insert some records in the table using insert command −mysql> insert into DemoTable(EmployeeName, EmployeeSalary, EmployeeExperience) values('Larry', 4500, 5); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(EmployeeName, EmployeeSalary, EmployeeExperience) values('Mike', 130000, 8); Query OK, 1 row affected (0.21 sec) mysql> ... Read More

How do I find out the default server character set in MySQL?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

284 Views

You can use system variables character_set_server to know the default server character set in MySQL. Following is the syntax −SHOW VARIABLES LIKE 'character_set_server';Additionally, to u can use collation_server system variable to know the default collation in MySQL. Following is the syntax −SHOW VARIABLES LIKE 'collation_server';Let us execute the above syntaxes to know the default character set and collation.Following is the query −mysql> SHOW VARIABLES LIKE 'character_set_server';This will produce the following output −+----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | character_set_server | utf8 | +----------------------+-------+ 1 row in set (0.25 sec)Following is the ... Read More

How to copy data from one field to another on every row in MySQL?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

2K+ Views

To copy data from one field to another on every row, use the UPDATE command.Let us first create a table −mysql> create table DemoTable    (    StudentId int,    StudentFirstName varchar(20),    StudentMarks int default 0    ); Query OK, 0 rows affected (0.49 sec)Following is the query to insert records in the table using insert command −mysql> insert into DemoTable(StudentId, StudentFirstName) values(89, 'Larry'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentId, StudentFirstName) values(35, 'Robert'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(StudentId, StudentFirstName) values(48, 'Chris'); Query OK, 1 row affected (0.13 sec) ... Read More

MySQL query to retrieve records from the part of a comma-separated list?

Samual Sam
Updated on 30-Jul-2019 22:30:25

449 Views

To retrieve records from the part of a comma-separated list, you can use built in function FIND_IN_SET().Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20),    Marks varchar(200)    ); Query OK, 0 rows affected (0.61 sec)Following is the query to insert some records in the table using insert command −mysql> insert into DemoTable(Name, Marks) values('Larry', '98, 34, 56, 89'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Name, Marks) values('Chris', '67, 87, 92, 99'); Query OK, 1 row affected (0.15 sec) mysql> insert ... Read More

How to call a stored procedure using select statement in MySQL?

Rama Giri
Updated on 30-Jul-2019 22:30:25

5K+ Views

In MySQL, it is not possible to use select from procedure in FROM clause. You can use CALL command and after that the SELECT statement can be executed.Let us first create a table:mysql> create table DemoTable2    -> (    -> CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> CustomerName varchar(100),    -> ShippingDateTime datetime    -> ); Query OK, 0 rows affected (0.66 sec)Following is the query to create stored procedure:mysql> DELIMITER // mysql> CREATE PROCEDURE insert_information(Name varchar(100), shippingtime datetime)    -> BEGIN    ->    -> INSERT INTO DemoTable2(CustomerName, ShippingDateTime) VALUES(Name, shippingtime);    -> END    -> ... Read More

How to work with array variable in MySQL?

Rama Giri
Updated on 30-Jul-2019 22:30:25

2K+ Views

MySQL does not support array variables. To get the same result, use the table DUAL. Following is the syntax:SELECT yourValue1 AS ArrayValue FROM DUAL UNION ALL SELECT yourValue2 FROM DUAL UNION ALL SELECT yourValue3 FROM DUAL UNION ALL SELECT yourValue4 FROM DUAL UNION ALL . . . . . . SELECT yourValueN FROM DUAL;Let us create a sample table:mysql> SELECT 1 AS ArrayValue FROM DUAL       UNION ALL       SELECT 2 FROM DUAL       UNION ALL       SELECT 3 FROM DUAL       UNION ALL       SELECT 4 FROM ... Read More

Deleting the nth row in MySQL?

Rama Giri
Updated on 30-Jul-2019 22:30:25

774 Views

To delete nth row in MySQL, use DELETE statement and work with subquery. Let us first create a table:mysql> create table DemoTable1    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(100)    -> ); Query OK, 0 rows affected (0.99 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable1(StudentName) values('Larry'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1(StudentName) values('Sam'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1(StudentName) values('Mike'); Query OK, 1 row affected (0.18 sec) mysql> ... Read More

Advertisements