Sharon Christine has Published 461 Answers

If I truncate a table, should I also add indexes?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:19:51

If you truncate a table, you do not need to add indexes because table is recreated after truncating a table and indexes get added automatically.Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FirstName varchar(20), ... Read More

MySQL query to return a substring after delimiter?

Sharon Christine

Sharon Christine

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

Use SUBSTRING() to return values after delimiter. Let us first create a table −mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John is good in MySQL, Sam is ... Read More

Selecting data from a MySQL table based on a specific month?

Sharon Christine

Sharon Christine

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

Use the MONTH() method in MySQL to select date based on month. Let us first create a table −mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(10), -> UserPostMessageDate datetime, -> UserLikes int -> ); Query OK, 0 rows affected (0.77 sec)Insert ... Read More

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

Previous 1 ... 3 4 5 6 7 8 9 ... 47 Next
Advertisements