Find Records Not in Set Array with MySQL

AmitDiwan
Updated on 22-Aug-2019 07:17:39

3K+ Views

For this, you can use NOT IN() function.Let us first create a table −mysql> create table DemoTable718 (    Id int,    FirstName varchar(100),    Age int ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable718 values(101, 'Chris', 26); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable718 values(102, 'Robert', 24); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable718 values(103, 'David', 27); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable718 values(104, 'Mike', 28); Query OK, 1 row affected (0.19 sec) mysql> ... Read More

Sort VARCHAR Data with Both String and Number Values in MySQL

AmitDiwan
Updated on 22-Aug-2019 07:17:28

127 Views

For this, you can use ORDER BY IF(CAST()). Let us first create a table −mysql> create table DemoTable(EmployeeCode varchar(100)); Query OK, 0 rows affected (1.17 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('190'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('100'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('120'); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------------+ ... Read More

Create a Random Four-Digit Number in MySQL

AmitDiwan
Updated on 22-Aug-2019 07:15:42

924 Views

Let us first create a table −mysql> create table DemoTable717 (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserPassword int ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command −mysql> insert into DemoTable717(UserPassword) values(1454343); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable717(UserPassword) values(674654); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable717(UserPassword) values(989883); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable717(UserPassword) values(909983); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable717;This will produce ... Read More

Print Numbers in Sequence Using Thread Synchronization in C

Sunidhi Bansal
Updated on 22-Aug-2019 07:15:18

7K+ Views

Given with the threads the program must print the thread based on their priorities starting from 0 to 10.What is a thread?Thread is lightweight process that runs inside a program. A simple program can contain n number of threads.Unlike java, multithreading is not supported by the language standards, POSIX Threads (Pthreads) is the standard used in multithreading in C/C++. C does not contain any built-in support for multithreaded applications. Instead, it relies entirely upon the operating system to provide this feature.How it works in our program?To use the thread functions we use header file #include. This header file will include ... Read More

Update Multiple Values in a Table with MySQL IF Statement

AmitDiwan
Updated on 22-Aug-2019 07:14:13

474 Views

Let us first create a table −mysql> create table DemoTable716 (    Id varchar(100),    Value1 int,    Value2 int,    Value3 int ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable716 values('100', 45, 86, 79); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable716 values('101', 67, 67, 99); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable716 values('102', 77, 57, 98); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable716 values('103', 45, 67, 92); Query OK, 1 row affected (0.16 sec)Display all ... Read More

Order By Length of Column in MySQL

AmitDiwan
Updated on 22-Aug-2019 07:12:25

900 Views

To order by length of column in MySQL, use ORDER BY LENGTH.Let us first create a table −mysql> create table DemoTable715 (UserMessage varchar(100)); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable715 values('Aw'); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable715 values('Awe'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable715 values('A'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable715 values('Awes'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable715 values('Awesom'); Query OK, 1 row affected (0.16 sec) mysql> insert ... Read More

Print Leftmost and Rightmost Nodes of a Binary Tree in C

Sunidhi Bansal
Updated on 22-Aug-2019 07:11:00

1K+ Views

Given a binary tree with left and right children and the task is to print the exact right and left child of the given tree.Leftmost nodes are the nodes which are associated on the left side from the parent node of the tree and rightmost nodes are which are associated on the right side from the parent node of the root.ExampleInput: 106 20 320 100 21 61 52 Output: 106 20 320 100 52AlgorithmStart Step 1 -> create structure of a node    Declare int data    Declare struct node *left and *right Step 2 -> create struct node* newNode(int ... Read More

MySQL Query to Count Rows in Multiple Tables

AmitDiwan
Updated on 22-Aug-2019 07:10:45

1K+ Views

Let us first create a table −mysql> create table DemoTable1 (FirstName varchar(100)); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values('Bob'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1 values('James'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1 values('John'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1 values('David'); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output -+-----------+ | FirstName | +-----------+ | Bob ... Read More

Compare Date Strings in MySQL

AmitDiwan
Updated on 22-Aug-2019 07:07:00

2K+ Views

To compare date strings, use STR_TO_DATE() from MySQL.Let us first create a table −mysql> create table DemoTable712 (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ArrivalDate varchar(100) ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable712(ArrivalDate) values('10.01.2019'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable712(ArrivalDate) values('11.12.2018'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable712(ArrivalDate) values('01.11.2017'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable712(ArrivalDate) values('20.06.2016'); Query OK, 1 row affected (0.23 sec)Display all records from the table using select ... Read More

MySQL Query to Get Records After an Interval of 8 Months

AmitDiwan
Updated on 22-Aug-2019 07:06:51

174 Views

For this, use INTERVAL 8 MONTH and fetch records 8 months from the current date −select *from yourTableName where yourColumnName>= (CURRENT_DATE() - INTERVAL 8 MONTH);Note − Let’s say the current date is: 2018-02-06Let us first create a table −mysql> create table DemoTable (StudentName varchar(100), AdmissionDate date); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', '2019-01-21'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('Chris', '2019-10-04'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values('Robert', '2018-02-01'); Query OK, 1 row affected (0.16 sec) ... Read More

Advertisements