How to display a single quote text as a column value in MySQL?

AmitDiwan
Updated on 03-Oct-2019 07:51:46

179 Views

To display a single quote text, use double quotes like if you want to write You’ve, then write You've while inserting i.e. with double-quotes. Let us first create a table −mysql> create table DemoTable (    Note text ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('You''ve seen the Taj? When?'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('You''ve visited the US?'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More

Updating blank cells to NULL will cause all cells to be NULL in MySQL?

AmitDiwan
Updated on 03-Oct-2019 07:49:27

63 Views

To update only blank cells to NULL, use NULLIF() in MySQL. Let us first create a table −mysql> create table DemoTable (    Name varchar(50) ); Query OK, 0 rows affected (1.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(''); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(''); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.15 ... Read More

How to implement MAX(distinct…) in MySQL and what is the difference without using DISTINCT?

AmitDiwan
Updated on 03-Oct-2019 07:47:26

2K+ Views

Let us see the first syntax, which uses DISTINCT in MAX() −select max(DISTINCT yourColumnName) from yourTableName;The second syntax is as follows. It isn’t using DISTINCT −select max( yourColumnName) from yourTableName;NOTE − Both the above queries give the same result with or without a DISTINCT keyword. MySQL internally converts MAX(yourColumnName) to DISTINCT keyword.Let us now see an example and create a table −mysql> create table DemoTable (    Number int ); Query OK, 0 rows affected (1.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(80); Query OK, 1 row affected (0.09 sec) mysql> insert into ... Read More

How can I trigger a JavaScript click event?

Prabhas
Updated on 03-Oct-2019 07:46:57

1K+ Views

To trigger a JavaScript click event, let us see the example of mouse hover.ExampleLive Demo           Hover over the button.                                      function display() {             document.getElementById("test").click();          }          

In MySQL stored procedures, how to check if a local variable is null?

AmitDiwan
Updated on 03-Oct-2019 07:43:52

331 Views

For this, use COALESCE(). Let us implement a stored procedure to check if the local variable is null −mysql> DELIMITER // mysql> CREATE PROCEDURE local_VariableDemo()    BEGIN    DECLARE value1 int;    DECLARE value2 int;    select value1, value2;    select    concat('After checking local variable is null the sum is = ', COALESCE(value1, 0)+COALESCE(value2, 0)); END // Query OK, 0 rows affected (0.19 sec) mysql> DELIMITER ;Call the stored procedure using CALL command −mysql> call local_VariableDemo();This will produce the following output −+--------+--------+ | value1 | value2 | +--------+--------+ | NULL | NULL | +--------+--------+ 1 ... Read More

SET only two values for all the rows in a MySQL table based on conditions?

AmitDiwan
Updated on 03-Oct-2019 07:40:10

80 Views

For condition based update, use UPDATE and IF(). Let us first create a table −mysql> create table DemoTable (    Value int ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.10 sec)Display all records ... Read More

How can I match a comma separated list against a value in MySQL?

AmitDiwan
Updated on 03-Oct-2019 07:38:18

962 Views

Let us first create a table −mysql> create table DemoTable (    `Values` varchar(50) ); Query OK, 0 rows affected (1.15 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('23, 45, 78, 56'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('384, 476, 7456'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('68, 8, 88, 89'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('78, 80, 84'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This ... Read More

MySQL query to fetch only a single field on the basis of boolean value in another field

AmitDiwan
Updated on 03-Oct-2019 07:35:20

153 Views

Let us first create a table −mysql> create table DemoTable (    EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    EmployeeName varchar(40),    isMarried boolean ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(EmployeeName, isMarried) values('Chris', true); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(EmployeeName, isMarried) values('Robert', false); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(EmployeeName, isMarried) values('Mike', false); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(EmployeeName, isMarried) values('Bob', true); Query OK, 1 row affected (0.07 sec) mysql> insert into ... Read More

How to insert an array of values in a MySQL table with a single INSERT?

AmitDiwan
Updated on 03-Oct-2019 07:32:56

4K+ Views

Let us first create a table −mysql> create table DemoTable (    ClientId int,    ClientName varchar(50) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. Here, we are inserting multiple values using only a single INSERT −mysql> insert into DemoTable values(101,'Adam'),(102,'Chris'),(103,'Robert'),(104,'Sam'),(105,'Mike'); Query OK, 5 rows affected (0.16 sec) Records: 5 Duplicates: 0 Warnings: 0Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----------+------------+ | ClientId | ClientName | +----------+------------+ | 101 | Adam | | 102 | Chris | | 103 | Robert | | 104 | Sam | | 105 | Mike | +----------+------------+ 5 rows in set (0.00 sec)

How to structure some data in a MySQL database for easier retrieval?

AmitDiwan
Updated on 03-Oct-2019 07:31:12

58 Views

You can use FIND_IN_SET to structure some data in a database for easier retrieval. Let us first create a table −mysql> create table DemoTable (    CountryName SET('US', 'UK', 'AUS') ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('US'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('UK'); Query OK, 1 row affected (0.09 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-------------+ | CountryName | +-------------+ | US ... Read More

Advertisements