Combine Multiple Text Records to One in MySQL

AmitDiwan
Updated on 17-Dec-2019 06:04:48

264 Views

To combine multiple text records, use GROUP_CONCAT(). Let us first create a table −mysql> create table DemoTable1611    -> (    -> Value text    -> ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1611 values('John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1611 values('is'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1611 values('learning'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1611 values('Java'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1611 values('with'); Query OK, 1 row affected ... Read More

Custom Sorting Using Two Different Columns in MySQL

AmitDiwan
Updated on 17-Dec-2019 06:01:17

229 Views

For this, use ORDER BY clause along with CASE statement. Let us first create a table −mysql> create table DemoTable1610    -> (    -> Marks int,    -> Name varchar(20)    -> ) ; Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1610 values(85, 'John'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1610 values(78, 'Carol'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1610 values(78, 'John'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1610 values(85, 'Carol'); Query OK, 1 row affected ... Read More

Use Delimiter in a MySQL Stored Procedure

AmitDiwan
Updated on 17-Dec-2019 05:59:31

333 Views

The correct way is as follows −DELIMITER // CREATE PROCEDURE yourStoredProcedureName() BEGIN  IF  yourCondition then      yourStatement1 ; else     yourStatement2 ; END IF ; END // DELIMITER ;Let us now see an example and create a stored procedure −mysql> DELIMITER // mysql> CREATE PROCEDURE delimiter_demo()    -> BEGIN    -> IF 1 THEN    -> SELECT "If condition will always true";    -> else    -> select "No" ;    -> END IF ;    -> END    -> // Query OK, 0 rows affected (0.17 sec) mysql> DELIMITER ;Now you can call the ... Read More

Select Minimum Value from Maximum Values of Two Tables in MySQL

AmitDiwan
Updated on 17-Dec-2019 05:58:03

191 Views

For this, you can use UNION in MySQL. Let us first create a table −mysql> create table DemoTable1    -> (    -> Value int    -> )    -> ; Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(60); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1 values(78); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1 values(57); Query OK, 1 row affected (0.08 sec)Display all records from the table using select statement −mysql> select * from DemoTable1; This will produce the following ... Read More

Minimum MySQL User Privileges for Optimize and Repair

AmitDiwan
Updated on 17-Dec-2019 05:51:08

415 Views

The select and insert statements are the minimum required MySQL user privileges to allow optimize and repair.You can use below syntax to give insert and select privileges to the user −grant insert, select on yourDatabaseName.* to 'yourUserName'@'localhost';At first, here is the query to create a user −mysql> create user 'Emma'@'localhost' identified by 'Emma123'; Query OK, 0 rows affected (0.26 sec)Here is the query to give grants for the above user −mysql> grant insert, select on web.* to 'Emma'@'localhost'; Query OK, 0 rows affected (0.21 sec)Here is the query to display all grants of the above user −mysql> show grants for ... Read More

Implement MySQL LIKE Query in SQL

AmitDiwan
Updated on 17-Dec-2019 05:41:49

189 Views

To implement a query like MySQL IN(), you need to use COUNT(), IF() along with LIKE operator. Let us first create a table −mysql> create table DemoTable    -> (    -> Subject varchar(80)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('MySQLMongoDB'); Query OK, 1 row affected (0.86 sec) mysql> insert into DemoTable values('MySQL'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('JavaMySQL'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('MongoDB'); Query OK, 1 row affected (0.20 sec) ... Read More

Fetch Maximum Value from Multiple Columns with Null and Non-Null Values

AmitDiwan
Updated on 17-Dec-2019 05:39:49

468 Views

For this, you can use COALESCE(). For the maximum value, use GREATEST() in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Value1 int,    -> Value2 int,    -> Value3 int    -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(NULL, 80, 76); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(NULL, NULL, 100); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(56, NULL, 45); Query OK, 1 row affected (0.20 sec) mysql> ... Read More

Format MySQL Records Price Values After Multiplying Them

AmitDiwan
Updated on 17-Dec-2019 05:36:53

201 Views

To format records, use FORMAT(). Let us first create a table −mysql> create table DemoTable    -> (    -> Price decimal(10, 4),    -> Rate decimal(10, 4)    -> ); Query OK, 0 rows affected (0.96 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1000, 10.2); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(2000, 20.4); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(100, 5); 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

MySQL LIKE Command with Strings Containing Dots

AmitDiwan
Updated on 17-Dec-2019 05:34:46

516 Views

To work with strings containing dots, and display records beginning with a specific number, you need to use REGEXP. Let us first create a table −mysql> create table DemoTable    -> (    -> GameReleaseVersion varchar(20)    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('19.6'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('18.4'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('17.6'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('19.5'); Query OK, 1 row affected ... Read More

Set Capacity of SortedList Object in C#

AmitDiwan
Updated on 16-Dec-2019 12:37:04

139 Views

To set the capacity to the actual number of elements in a SortedList object, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       SortedList sortedList = new SortedList();       sortedList.Add("A", "1");       sortedList.Add("B", "2");       sortedList.Add("C", "3");       sortedList.Add("D", "4");       sortedList.Add("E", "5");       sortedList.Add("F", "6");       sortedList.Add("G", "7");       sortedList.Add("H", "8");       sortedList.Add("I", "9");       sortedList.Add("J", "10");       Console.WriteLine("SortedList elements...");     ... Read More

Advertisements