Is there a way in MySQL to reverse a boolean field with a single query?

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

1K+ Views

Yes, you can use if() function from MySQL to reverse a boolean field. The syntax is as follows −UPDATE yourTableName SET yourBooleanColumnName = IF(yourBooleanColumnName, 0, 1);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ReverseBooleanField    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> isValid BOOLEAN    -> ,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into ReverseBooleanField(isValid) values(true); ... Read More

Using LIKE for two where clauses in MySQL?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

228 Views

You don’t need to use two where clauses. Use two conditions using the LIKE operator and AND operator.To understand how to use LIKE for this, let us create a table. The query to create a table is as follows −mysql> create table WhereDemo    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into WhereDemo values(101, 'Maxwell'); Query OK, 1 row affected (0.14 sec) mysql> insert into WhereDemo values(110, 'David'); Query ... Read More

Sum values of a single row in MySQL?

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

1K+ Views

You can use below syntax to sum values of a single row −Case 1 − The following is the syntax if your column does not have NULL value −SELECT yourColumnName1+yourColumnName2+yourColumnName3+.......+N as anyVariableName FROM yourTableName;Case 2 − If your column has NULL value then use this syntax −SELECT IFNULL(yourColumnName1, 0)+ IFNULL(yourColumnName2, 0)+ IFNULL(yourColumnName3, 0)+.............+N 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 SumValueOfSingleRow    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> FirstValue int,    -> SecondValue int,    -> ThirdValue ... Read More

Which are the universities in the US that give scholarships in script writing?

Ridhi Arora
Updated on 30-Jul-2019 22:30:24

178 Views

Creative writing allows to express one’s thoughts, emotions, and feelings along with the information shared or in the form of the information shared. One may have the dream to pursue scriptwriting from the U.S. A, but if one thinks that due to lack of finances this dream may never turn into reality; one is bound to be ignorant of the leading universities providing scholarship there.List of Universities of the U.S.A. Providing Scholarship for Script WritingLake Forest College in Chicago, Illinois, distributes scholarships to deserving applicants. The award amounts range between $1, 000-$5, 000 per academic year and are decided on ... Read More

MySQL "not a variable or NEW pseudo-variable" message. What is this error in my Stored Procedure?

Samual Sam
Updated on 30-Jul-2019 22:30:24

2K+ Views

To get rid of this error message, let us see a sample example. But before that let us go through the concept to fix it.Use variable to get the value from stored procedure. The variable will prefix with @ symbol. The syntax is as follows −CALL yourStoredProcedureName(yourParameter1, yourParameter2, ..........N, @yourVariableName);To see the value of variable you need to use select statement. The syntax is as follows −SELECT @yourVariableName;To understand the above syntax, let us create a table and insert some records in the table.The query to create a table is as follows −mysql> create table StoredProcedureDemo    -> (   ... Read More

Create MySQL column with Key=MUL?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

6K+ Views

You need to use ADD KEY to make a column with Key=MUL. The syntax is as follows −ALTER TABLE yourTableName MODIFY COLUMN yourColumnName data type, ADD KEY(yourColumnName);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Instructor    -> (    -> Instructor_Id int,    -> Instructor_Name varchar(30),    -> Instructor_CourseName varchar(100)    -> ); Query OK, 0 rows affected (0.63 sec)Now you can look the table description of the table, the column KEY does not have any MUL key. The query is as follows to check the ... Read More

How do I pass a variable to a MySQL script?

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

4K+ Views

You can pass a variable to a MySQL script using session variable. First you need to set a session variable using SET command. After that you need to pass that variable to a MySQL script.The syntax is as follows −First Step: Use of Set command.SET @anyVariableName − = ’yourValue’;Second Step: Pass a variable to a MySQL script.UPDATE yourTableName SET yourColumnName1 = yourColumnName1+integerValue WHERE yourColumnName2 = @anyVariableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Employee_Information    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT,    -> ... Read More

What is the significance of dandy in Oscar Wilde's plays?

Ridhi Arora
Updated on 30-Jul-2019 22:30:24

590 Views

By the last decade of the nineteenth century, Drama as an occupation and the theatre as a profession had undergone huge changes. In the last three decades of the century with the famous playwrights Oscar Wilde (1865-1900), George Bernard Shaw (1856-1950), Sydney Grundy (1848-1914) the theatre began to gain a refined literary tone.Wilde’s Writing StyleWilde managed to collaborate the attributes, from a wide range of styles, practices, and genres, from drama, fiction and lyric, into finely patterned theatre events. He used satire, a scintillating wit, symbolism, literariness and farcical situations in his plays. His plays are aristocratic in its outlook, ... Read More

MySQL CREATE USER with a variable?

Samual Sam
Updated on 30-Jul-2019 22:30:24

1K+ Views

You can use a dynamic query for this. First set the variable name for username and variable name for a password. The syntax is as follows −SET @anyVariableName=’yourUserName’; SET @anyVariableName1=’yourpassword’;Now you can use the CONCAT() function from MySQL. The syntax is as follows −SET @yourQueryName = CONCAT ('    CREATE USER "', @anyVariableName, '"@"localhost" IDENTIFIED BY "', @anyVariableName1, '" ' );Let us use the prepared statement PREPARE. The syntax is as follows −PREPARE yourStatementVariableName FROM @yourQueryName;Now you can execute the statement. The syntax is as follows −EXECUTE yourStatementVariableName;Deallocate the above using the DEALLOCATE PREPARE. The syntax is as follows −DEALLOCATE ... Read More

How to quote values using MySQL group_concat?

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

1K+ Views

You can quote values using concat() and grop_concat() function from MySQL. The syntax is as follows −SELECT GROUP_CONCAT(CONCAT(' '' ', 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 Group_ConcatDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT,      -> Value int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (1.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into Group_ConcatDemo(Value) ... Read More

Advertisements