MySQL Query for Text Search Using LIKE and OR

AmitDiwan
Updated on 10-Oct-2019 11:45:16

140 Views

Let us first create a table −mysql> create table DemoTable (    Subject text ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Introduction to MySQL'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values('Deep Dive using Java'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('C in Depth'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Introduction to C++'); Query OK, 1 row affected (0.48 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will ... Read More

Select Query for a Specific Day Using MySQL

AmitDiwan
Updated on 10-Oct-2019 11:43:16

86 Views

Let us first create a table −mysql> create table DemoTable (    Joiningdate date ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2010-01-01'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2010-03-31'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2010-11-04'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('2012-12-31'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('2019-01-03'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2016-04-05'); Query OK, 1 row affected ... Read More

Compare Date When Admission Date is Less Than Current Date in MySQL

AmitDiwan
Updated on 10-Oct-2019 11:41:28

331 Views

Let us first create a table −mysql> create table DemoTable (    AdmissionDate varchar(50) ); Query OK, 0 rows affected (0.63 sec)Note − Let’s say the current date is 14-Sep-2019.Insert some records in the table using insert command. Following is the query −mysql> insert into DemoTable values('15-Sep-2019'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('14-Sep-2019'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('13-Sep-2016'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('13-Sep-2019'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('13-Sep-2020'); Query OK, 1 row affected ... Read More

Implement Nested INSERT with SELECT in MySQL

AmitDiwan
Updated on 10-Oct-2019 11:39:16

661 Views

Yes, we can implement nested insert with select in MySQL as shown in the below syntax −insert into yourTableName2(yourColumnName1, yourColumnName2, .....N) select yourColumnName1, yourColumnName2, ....N from yourTableName1 where yourCondition;Let us first see an example and create a table −mysql> create table DemoTable1 (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(40) ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(Name) values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1(Name) values('David'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1(Name) values('Bob'); Query ... Read More

MySQL CASE WHEN with SELECT to Display Odd and Even IDs

AmitDiwan
Updated on 10-Oct-2019 11:36:14

2K+ Views

Let us first create a table −mysql> create table DemoTable (    PageId int ); Query OK, 0 rows affected (0.85 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(233); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable values(34); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(76); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.26 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------+ | PageId | +--------+ ... Read More

Perform Multi-Table Delete in MySQL

AmitDiwan
Updated on 10-Oct-2019 11:33:23

210 Views

For this, you can use DELETE command. Let us first create a table −mysql> create table DemoTable1 (    Id int,    Name varchar(20) ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(1, 'Chris'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1 values(2, 'David'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1 values(3, 'Bob'); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+------+-------+ | Id   ... Read More

Replace All Occurrences of a Word in a String with Another Word in Java

Maruthi Krishna
Updated on 10-Oct-2019 10:40:12

1K+ Views

The replaceAll() method of the String class accepts two strings, One representing a regular expression to find a string and the other representing a replacement string.And, replaces all the matched sequences with the given String. Therefore, to replace a particular word with another in a String −Get the required String.Invoke the replace all method on the obtained string by passing, a regular expression representing the word to be replaced (within word boundaries “\b”) and a replacement string as parameters.Retrieve the result and print it.Exampleimport java.io.File; import java.io.IOException; import java.util.Scanner; public class ReplacingWords {    public static void main(String[] args) throws ... Read More

Role of the String intern() Method in Java

Maruthi Krishna
Updated on 10-Oct-2019 08:55:14

132 Views

A String is a class in Java which stores a sequence of characters, it belongs to the java.lang package. Once you create a String object you cannot modify them (immutable).StorageAll String objects are stored in a separate memory location in the heap area known as, String Constant pool.Whenever you define a String value JVM creates a String object with the given value in the String constant pool. Therefore, if you run the above program two String values are created in the String constant pool.The intern() methodThis method returns value of the current String from the pool of unique String values. ... Read More

Mix Two Strings to Generate Another in Java

Maruthi Krishna
Updated on 10-Oct-2019 08:20:46

14K+ Views

Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other primitive datatype).String stringObject = new String("Hello how are you"); String stringLiteral = "Welcome to Tutorialspoint";Concatenating StringsYou can concatenate Strings in Java in the following ways −Using the "+" operator − Java Provides a concatenation operator using this, you can directly add two String literalsExampleimport java.util.Scanner; public class StringExample {   ... Read More

StringJoiner in Java 8

Maruthi Krishna
Updated on 10-Oct-2019 07:05:21

171 Views

Since Java8 StringJoiner class is introduced this you can construct a sequence of characters separated by desired delimiter.Sr.NoConstructor & Description1StringJoiner(CharSequence delimiter)This constructor creates an empty (no characters) StringJoiner, just with a copy of the specified delimiter.2StringJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix)This constructs a StringJoiner without characters.Methods of StringJoiner classadd() − This method accepts a CharacterSequence object (Segment, String, StringBuffer, StringBuilder) and adds it to the current Joiner separating the next and previous elements (if any) with delimiter at the time of constructing it.Exampleimport java.util.StringJoiner; public class StringJoinerExample {    public static void main(String args[]) {       StringJoiner joiner ... Read More

Advertisements