Let us first create a table −mysql> create table DemoTable ( UserId int, UserName varchar(100) ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(101, 'Robert'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(102, 'David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(103, 'Mike'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More
Get similar results using MySQL IN(). Let us first create a table −mysql> create table DemoTable ( ClientId int, ClientName varchar(100), ClientAge int ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris', 34); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(101, 'Robert', 31); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(103, 'David', 33); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(104, 'Mike', 45); Query OK, 1 row affected (0.17 sec) mysql> insert ... Read More
In this article, we will learn about the Linear Search and its implementation in Python 3.x. Or earlier.AlgorithmStart from the leftmost element of given arr[] and one by one compare element x with each element of arr[]If x matches with any of the element, return the index value.If x doesn’t match with any of elements in arr[] , return -1 or element not found.Now let’s see the visual representation of the given approach −Example Live Demodef linearsearch(arr, x): for i in range(len(arr)): if arr[i] == x: return i return -1 arr = ... Read More
For this, you can use the ORDER BY CASE statement. Let us first create a table −mysql> create table DemoTable ( DueDate date ); Query OK, 0 rows affected (0.56 sec)Note − Let’s say the current date is 2019-07-22.Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-03-10'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-08-25'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-06-01'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('2019-12-31'); Query OK, 1 row affected (0.17 sec)Display all records from the ... Read More
Let us first create a table −mysql> create table DemoTable ( id int ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable values(7); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(8); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(6); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(9); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(11); Query OK, 1 row affected ... Read More
Let us first create a table −mysql> create table DemoTable ( Value varchar(100) ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('€986'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('§97'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------+ | Value | +--------+ | €986 | | §97 +--------+ 2 rows in set (0.00 sec)Following is the query to remove unconvertable characters to ASCII ... Read More
In this article, we will learn about the implementation of Insertion sort in Python 3.x. Or earlier.AlgorithmIterate over the input elements by growing the sorted array at each iteration.Compare the current element with the largest value available in the sorted array.If the current element is greater, then it leaves the element in its place and moves on to the next element else it finds its correct position in the sorted array and moves it to that position in the array.This is achieved by shifting all the elements towards the right, which are larger than the current element, in the sorted ... Read More
To select distinct values from two columns, use UNION. Let us first create a table −mysql> create table DemoTable1 ( Value1 int ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(1); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1 values(2); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1 values(3); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1 values(4); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will ... Read More
Let us first create a table −mysql> create table DemoTable ( StudentId int, StudentName varchar(100) ); Query OK, 0 rows affected (0.85 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(NULL, 'Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(NULL, 'Robert'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(101, 'David'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(102, 'Mike'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(103, 'Sam'); Query OK, 1 row affected (0.18 sec)Display all records ... Read More
In this article, we will learn about the solution to the problem statement given below −Problem statementWe will be given an array of number and we need to find the greatest common divisor.If we need to find gcd of more than two numbers, gcd is equal to the product of the prime factors common to all the numbers provided as arguments. It can also be calculated by repeatedly taking the GCDs of pairs of numbers of arguments.Here we will be implementing the latter approachSo now, let’s see the implementationExample Live Demodef findgcd(x, y): while(y): x, y = ... Read More