Found 4381 Articles for MySQL

How to open MySQL command line on Windows10?

Ankith Reddy
Updated on 30-Jun-2020 12:38:34

24K+ Views

To open the MySQL command line from cmd, you need to use username root with your password.Follow the below given steps. The syntax is as follows −cd \> press enter key cd Program Files\MySQL\MySQL Server 8.0\bin> press enter key C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -uroot -p press enter key Enter password: ******Here is the step by step instruction to open MySQL command line. First, Go to START > RUN or Open Run using Windows+R command −Type CMD and hit OK button −After pressing OK button, the CMD will open −Now you need to follow the above instruction. First reach your bin ... Read More

How to use GROUP BY to concatenate strings in MySQL and how to set a separator for the concatenation?

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

9K+ Views

To concatenate strings in MySQL with GROUP BY, you need to use GROUP_CONCAT() with a SEPARATOR parameter which may be comma(‘) or space (‘ ‘) etc.The syntax is as follows:SELECT yourColumnName1, GROUP_CONCAT(yourColumnName2 SEPARATOR ‘yourValue’) as anyVariableName FROM yourTableName GROUP BY yourColumnName1;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table GroupConcatenateDemo    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.99 sec)Insert some records in the table using insert command. The query to insert record is as follows:mysql> insert ... Read More

When the MySQL delimiter error occur?

George John
Updated on 30-Jul-2019 22:30:24

2K+ Views

The MySQL delimiter occurs when you are using a pipe delimiter(|) with semicolon (;) and using MySQL version lower than 8.0.12.MySQL treats the pipe (|) as one delimiter and semicolon (;) is another delimiter. Therefore, do not confuse the MySQL delimiter with pipe as well as semicolon.Note: Here, we are using MySQL version 8.0.12. The pipe delimiter works fine with semicolon. If you are using version lower than 8.0.12, then this leads to a delimiter error.Here is the working of MySQL delimiter:mysql> delimiter |; mysql> create procedure getSumOfTwoNumbers() -> begin -> select 2+3 as ... Read More

MySQL: Insert a row and get the content?

Chandu yadav
Updated on 30-Jul-2019 22:30:24

146 Views

In order to do insert a row and get the content, you need to use stored procedure, First, you need to create a table. After that you need to create a stored procedure that will insert a row and get the content to the end user.To do the above task, let us first create a table. The query to create a table is as follows:mysql> create table InsertRecord_SelectTable -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> PRIMARY KEY(Id) -> ); Query ... Read More

How do you append a carriage return to a value in MySQL?

Arjun Thakur
Updated on 30-Jun-2020 12:30:09

1K+ Views

You need to use CONCAT_WS() function from MySQL to append a carriage return. If you are looking for a new line, then append in the beginning. The syntax is as follows −SELECT CONCAT_WS(‘’, yourColumnName) as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table NewLineDemo -> ( -> CountryName varchar(10) -> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into NewLineDemo values('US'); Query OK, 1 row affected (0.15 sec) ... Read More

How to get the sum for every distinct value in another column in MySQL?

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

3K+ Views

You can get the sum for every distinct value in another column with the help of aggregate function SUM() with GROUP BY command. To understand the above concept, let us create a table. The query to create a table is as follows:mysql> create table SumOfEveryDistinct -> ( -> Id int not null, -> Amount int -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command. The query is as follows:mysql> insert into SumOfEveryDistinct values(10, 100); Query OK, 1 row affected (0.19 ... Read More

MySQL stored procedure return value?

George John
Updated on 30-Jul-2019 22:30:24

14K+ Views

To return a value from stored procedure, you need to use user defined session specific variable. Add @ symbol before variable name.For example, use @symbol for variable valido. The syntax for the same is as follows:SELECT @valido;Whenever you use select statement, you need to use @anyVariableName. The syntax is as follows:SELECT @anyVariableName;Here is the demo of stored procedure of return value. The query to create a stored procedure is as follows:mysql> create procedure ReturnValueFrom_StoredProcedure -> ( -> In num1 int, -> In num2 int, -> out valido int ... Read More

Use a trigger to stop an insert or update in MySQL?

Venu Madhavi
Updated on 12-Feb-2025 12:08:03

5K+ Views

The MySQL trigger can be used to automatically terminate an INSERT or UPDATE operation if specific conditions are not met. This is achieved by adding logic to the trigger to detect incorrect data or violations of a rule. If the condition is satisfied, the SIGNAL statement is used to show a customized error message and terminate the procedure. Thus, it ensures that the database has valid, clean, and consistent data. For instance, if a value is being updated or inserted in the column beyond the allowed range, the trigger can stop the action and give a customized error message. ... Read More

Retrieve a large select by chunks in MySQL?

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

5K+ Views

To retrieve large select by chunks, you need to use ORDER BY LIMIT. The syntax is as follows:SELECT *FROM yourTableName ORDER BY yourColumnName LIMIT 0, 10;From the above syntax, you will get 10 rows from the table. In the above syntax, 0 represents the first row from the result set of a table that means it is zero index based. The second value of LIMIT represents the maximum number of rows that can be retrieved from the table.If you want the next rows after 10 to 30, then use in LIMIT like this. The syntax is as follows:SELECT *FROM yourTableName ... Read More

Split a string and loop through values in MySQL Procedure?

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

5K+ Views

To split a string and loop through all values in MySQL procedure, you do not need to use REPLACE() function. To understand, first create a stored procedure and after that create a table and call the stored procedure with some values. The value will be inserted into the table.The query to create a stored procedure is as follows:mysql> DELIMITER // mysql> CREATE PROCEDURE SP_SplitString(Value longtext)    -> BEGIN    -> DECLARE front TEXT DEFAULT NULL;    -> DECLARE frontlen INT DEFAULT NULL;    -> DECLARE TempValue TEXT DEFAULT NULL;    -> iterator:    -> LOOP      -> IF LENGTH(TRIM(Value)) ... Read More

Advertisements