Found 4219 Articles for MySQLi

How can I use another MySQL function/s with REPEAT() function?

Chandu yadav
Updated on 07-Feb-2020 10:09:17

58 Views

Suppose if we want to make the output of REPEAT() function more readable then we can use another function/s with it. For example, if we want to add space or some other character between the repeated values then we can use CONCAT() function.Examplemysql> Select REPEAT(CONCAT(' *', Subject, '* '), 3)AS Subject_repetition from student; +-----------------------------------------+ | Subject_repetition                      | +-----------------------------------------+ | *Computers* *Computers* *Computers*     | | *History* *History* *History*           | | *Commerce* *Commerce* *Commerce*        | | *Computers* *Computers* *Computers*     | ... Read More

How to repeat the values stored in a data column of MySQL table?

Akshaya Akki
Updated on 07-Feb-2020 10:08:05

139 Views

For repeating the values stored in a data column of MySQL table, the name of the column must be passed as the first argument of REPEAT() function. The data from ‘Student’ table is used to demonstrate it:Examplemysql> Select REPEAT(Name,3)AS Name from student; +-----------------------+ | Name                  | +-----------------------+ | GauravGauravGaurav    | | AaravAaravAarav       | | HarshitHarshitHarshit | | GauravGauravGaurav    | | YashrajYashrajYashraj | +-----------------------+ 5 rows in set (0.00 sec)

How can we use prepared statements in MySQL?

Nikitha N
Updated on 20-Jun-2020 10:45:58

373 Views

MySQL server supports prepared statements, which are useful when we want to run many queries that differ only in very small details. We can prepare a statement and then execute it multiple times and each time with different data values. Basically, prepared statements in MySQL take advantage of client/server binary protocol. Prepared statements provide enhanced performance because the complete statement is parsed only one by the server.Followings are the steps for using prepared statements in MySQL −Prepare the statement It is the first step in which we will prepare a statement by using PREPARE statement. For example, following is a statement ... Read More

How can we use SET statement to assign a SELECT result to a MySQL user variable?

radhakrishna
Updated on 20-Jun-2020 10:48:08

454 Views

For using the SET statement to assign a SELECT result to a user variable we need to write the SELECT statement as a subquery within parentheses. The condition is that the SELECT statement must have to return a single value. To make it understand we are using the data from ‘Tender’ table which is as follows −mysql> select * from Tender; +----+---------------+--------------+ | Sr | CompanyName   | Tender_value | +----+---------------+--------------+ | 1  | Abc Corp.     | 250.369003   | | 2  | Khaitan Corp. | 265.588989   | | 3  | Singla group. | 220.255997   | ... Read More

What happens if I will assign a value to a MySQL user variable using a statement that returns multiple rows?

Srinivas Gorla
Updated on 20-Jun-2020 10:48:56

102 Views

In case, if we will assign a value to a user variable using a statement that returns multiple rows then the value from the last row would be saved in that user variable because user variables can save the only single value. Following the example, in which we are using data from table ‘Tender’, will exhibit it −Examplemysql> select * from Tender; +----+---------------+--------------+ | Sr | CompanyName   | Tender_value | +----+---------------+--------------+ | 1  | Abc Corp.     |   250.369003 | | 2  | Khaitan Corp. |   265.588989 | | 3  | Singla group. |   220.255997 ... Read More

What MySQL would return if we refer a user variable which is not assigned any value explicitly?

mkotla
Updated on 20-Jun-2020 10:49:23

68 Views

In case, when we refer a user variable which is not assigned any value explicitly, MySQL would return NULL. In other words, its value would be NULL. Following example would illustrate it −mysql> Select @X, @Y, @Z, @S, @G; +------+-------+----------+------+------+ | @X   | @Y    | @Z       | @S   | @G   | +------+-------+----------+------+------+ | Ram  | Shyam | Students | 5000 | NULL | +------+-------+----------+------+------+ 1 row in set (0.00 sec)We can see from the above result set that @X, @Y, @Z and @S has been assigned values explicitly and they returned the values ... Read More

How to replicate a string for a specified number of times in MySQL?

Swarali Sree
Updated on 10-Feb-2020 05:37:30

142 Views

With the help of MySQL REPEAT() function, we can replicate a string for a specified number of times.SyntaxREPEAT(Str, No.)Here Str is the string which is to be replicated for a specified number of times.No. is the numerical value which indicates that how many times the string would be repeated.Examplemysql> Select REPEAT('#*',5); +----------------+ | REPEAT('#*',5) | +----------------+ | #*#*#*#*#*     | +----------------+ 1 row in set (0.00 sec)

What MySQL returns if the argument of QUOTE() function is NULL?

Ankith Reddy
Updated on 07-Feb-2020 07:15:41

73 Views

MySQL returns NULL if the argument of QUOTE() function is NULL.Examplemysql> Select QUOTE(NULL); +-------------+ | QUOTE(NULL) | +-------------+ | NULL         +-------------+ 1 row in set (0.00 sec) mysql> Select Name, QUOTE(NULL) from student where id = 1; +--------+-------------+ | Name   | QUOTE(NULL) | +--------+-------------+ | Gaurav | NULL        | +--------+-------------+ 1 row in set (0.08 sec)

How does MySQL QUOTE() function work with comparison values?

Arjun Thakur
Updated on 20-Jun-2020 10:42:27

85 Views

When QUOTE() function used with WHERE clause then the output depends upon the comparison values returned by WHERE clause. Following example will exhibit it −Examplemysql> Select Name, ID, QUOTE(Subject)AS Subject from Student WHERE Subject = 'History'; +-------+------+-----------+ | Name  | ID   | Subject   | +-------+------+-----------+ | Aarav | 2    | 'History' | +-------+------+-----------+ 1 row in set (0.00 sec)

Which MySQL function can be used to append values of a column with single quotes?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:21

65 Views

MySQL QUOTE() function can be used to append values of a column with single quotes. For this, we must have to pass column name as the argument of QUOTE() function. Data from ‘Student’ table is used to demonstrate it as follows Example mysql> Select Name, ID, QUOTE(Subject)AS Subject from Student; +---------+------+-------------+ | Name | ID | Subject | +---------+------+-------------+ | Gaurav | 1 | 'Computers' | | Aarav | 2 | 'History' | | Harshit | 15 ... Read More

Advertisements