MySQL Articles

Page 299 of 355

MySQL appears to DROP USER but user still exists in MySQL.users table?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 200 Views

First check all the user and host from MySQL.user table with the help of select statement as shown belowmysql> select user, host from MySQL.user;The following is the output+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | %         | | Manish           | %         | | User2            | %         | | mysql.infoschema | %         | | mysql.session    | %   ...

Read More

How to work with array variable in MySQL?\\n

Rama Giri
Rama Giri
Updated on 30-Jul-2019 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

Return null for date_format when input is null in MySQL?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 712 Views

Use IF() function to return null for date_format when input is null in MySQL. The syntax is as follows −SELECT IF(yourDateColumnName, date_format(yourDateColumnName, '%d/%m/%Y'), NULL) FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table returnNullWhenInputIsNullDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ShippingDate datetime    -> ); Query OK, 0 rows affected (1.21 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into returnNullWhenInputIsNullDemo(ShippingDate) values('2019-01-21'); Query OK, 1 row affected ...

Read More

Bulk change all entries for a particular field in MySQL?

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 406 Views

Let us first create a demo table −mysql> create table BulkChangeDemo    -> (    -> CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> CustomerName varchar(20),    -> isEducated boolean    -> ); Query OK, 0 rows affected (1.47 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into BulkChangeDemo(CustomerName, isEducated) values('Larry', true); Query OK, 1 row affected (0.09 sec) mysql> insert into BulkChangeDemo(CustomerName, isEducated) values('John', false); Query OK, 1 row affected (0.16 sec) mysql> insert into BulkChangeDemo(CustomerName, isEducated) values('Carol', false); Query OK, 1 row affected (0.25 sec) mysql> insert into BulkChangeDemo(CustomerName, ...

Read More

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

Rama Giri
Rama Giri
Updated on 30-Jul-2019 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

MySQL index on column of int type?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 665 Views

Adding an index on column of int type is a good choice to run your query faster whenever your table has lots of records.If your table has less records then it is not a good choice to use index on column of int type.To understand the concept, let us create a table. The query to create a table is as follows −mysql> create table indexOnIntColumnDemo    -> (    -> UserId int,    -> UserName varchar(20),    -> UserAge int,    -> INDEX(UserId)    -> ); Query OK, 0 rows affected (0.85 sec)Now check the description of table −mysql> desc ...

Read More

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

Samual Sam
Samual Sam
Updated on 30-Jul-2019 564 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

MySQL find/ replace string in fields?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 376 Views

To find/replace string in fields, the syntax is as follows −update yourTableName set yourColumnName =REPLACE(yourColumnName, yourOldValue, yourNewValue);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table FindReplaceDemo    -> (    -> FileId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FileDirectory text    -> ); Query OK, 0 rows affected (0.92 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into FindReplaceDemo(FileDirectory) values('C://User//MySQL'); Query OK, 1 row affected (0.19 sec) mysql> insert into FindReplaceDemo(FileDirectory) values('D://WebsiteImage//image1.jpg'); Query OK, ...

Read More

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

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 322 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

How to select or, shift to another database in MySQL using a JDBC API?

Vrundesha Joshi
Vrundesha Joshi
Updated on 30-Jul-2019 536 Views

In general, You can change the current database in MySQL using the USE query.SyntaxUse DatabaseName;To change the current database using JDBC API you need to:Register the driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement: Create a Statement object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the execute() method of the Statement interface.ExampleFollowing JDBC ...

Read More
Showing 2981–2990 of 3,543 articles
« Prev 1 297 298 299 300 301 355 Next »
Advertisements