Sharon Christine has Published 450 Articles

Can we combine MySQL IN AND LIKE operators?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:12:18

Yes, we can combine IN and LIKE operators in MySQL using LIKE and OR operator. Let us first create a table −mysql> create table DemoTable -> ( -> SubjectTitle text -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

Adding integers from a variable to a MySQL column?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:06:34

To set a variable, use MySQL SET. For adding integers from a variable, use UPDATE and SET as in the below syntax −set @anyVariableName:=yourValue; update yourTableName set yourColumnName=yourColumnName+ @yourVariableName;Let us first create a table −mysql> create table DemoTable -> ( -> Number int -> ); Query OK, 0 rows affected ... Read More

Is it impossible to add a column in MySQL specifically before another column?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:05:36

No, you can easily add a column before another column using ALTER.Note − To add a column at a specific position within a table row, use FIRST or AFTER col_name Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Name ... Read More

MySQL XOR operator with IN clause?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:03:58

MySQL XOR returns TRUE if one or the other operand (or expression) but not both is TRUE. The IN clause is used to specify a condition with any other MySQL query.Let us first create a tablemysql> create table DemoTable -> ( -> Num1 int, -> Num2 int -> ); Query ... Read More

Display records from two columns based on comparison in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 13:59:02

Let us first create a table −mysql> create table DemoTable -> ( -> Num1 int, -> Num2 int -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 200); Query OK, 1 row affected (0.13 sec) mysql> ... Read More

Count only null values in two different columns and display in one MySQL select statement?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 13:57:51

Use IS NULL to test for NULL value. Let us first create a table −mysql> create table DemoTable    -> (    -> Number1 int,    -> Number2 int    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

Change multiple columns in a single MySQL query?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 13:54:52

For this, use UPDATE and REPLACE() in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(100),    -> StudentCountryName varchar(100)    -> ); Query OK, 0 rows affected (0.67 sec)Insert some records ... Read More

How to set a string with hyphen and numbers in MySQL varchar?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 13:53:58

To set a string with hyphen and numbers, you need to use single quotes. For example, 'Customer-1234-899', 'Customer-9383-901', etc.Let us first create a table −mysql> create table DemoTable -> ( -> CustomerId varchar(100) -> ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command ... Read More

Extract the middle part of column values in MySQL surrounded with hyphens and display in a new column?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 13:52:20

Use the SUBSTR() method to extract the middle part of column values surrounded with hyphens, for example, “11-84848-11”.Let us first create a table −mysql> create table DemoTable -> ( -> Number varchar(100), -> Number1 varchar(100) -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using ... Read More

Discard last 3 characters of a field in MySQL

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 13:43:52

Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId varchar(100)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('STU-090'); Query OK, 1 row affected (0.16 sec) mysql> insert ... Read More

Previous 1 ... 4 5 6 7 8 ... 45 Next
Advertisements