Found 6702 Articles for Database

How to find all uppercase strings in a MySQL table?

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

757 Views

To find all upper case strings in a MySQL table, you need to use BINARY UPPER() function. The syntax is as follows:SELECT *FROM yourTableName WHERE yourColumnName=BINARY UPPER(yourColumnName);To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table FindUpperCaseDemo    -> (    -> Id int,    -> FirstName varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (1.04 sec)Insert some records in the table using insert command. The query is as follows:mysql> insert into FindUpperCaseDemo values(1, 'John', 23); Query OK, 1 row affected (0.17 sec) mysql> ... Read More

How to implement WHILE LOOP with IF STATEMENT MySQL?

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

393 Views

The following is an example to implement MySQL WHILE LOOP with IF statement. We are using in a stored procedureThe following is the query to create our stored procedure:mysql> DELIMITER // mysql> create procedure sp_getDaysDemo() -> BEGIN -> SELECT MONTH(CURDATE()) INTO @current_month; -> SELECT MONTHNAME(CURDATE()) INTO @current_monthname; -> SELECT DAY(LAST_DAY(CURDATE())) INTO @total_numberofdays; -> SELECT CAST(DATE_FORMAT(NOW() ,'%Y-%m-01') as DATE)INTO @check_weekday; -> SELECT DAY(@check_weekday) INTO @check_day; -> SET @count_days = 0; -> SET @workdays = 0; ... Read More

How to specify Decimal Precision and scale number in MySQL database using PHPMyAdmin?

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

2K+ Views

You need to select a database when you are creating a table. Right now, I have a sample database. The snapshot is as follows:Now you need to give the table name as well as the number of columns you want:After that you need to press Go button. Now, the following section would be visible:The DECIMAL requires two parameter i.e. Total Number of Digit and second one is DigitAfterDecimalPoint.The structure of DECIMAL is as follows:DECIMAL(X, Y)Here, X is TotalNumberOfDigit and Y is DigitAfterDecimalPoint.Let us see an example:DECIMAL(6, 4)Above, we will be having 6 digit sand 2 digit safter decimal point. For ... Read More

How to open MySQL command line on Windows10?

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

21K+ 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

8K+ 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

1K+ 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

97 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

935 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

2K+ 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

12K+ 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

Advertisements