Delete Table Rows in MySQL if String in Cell is Matched

AmitDiwan
Updated on 25-Sep-2019 12:27:43

274 Views

Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(100) ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('John Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Name) values('Carol Taylor'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Name) values('John Doe'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Name) values('Chris Brown'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Name) values('John Brown'); Query OK, 1 row ... Read More

Print Matrix in Z Form using Python

Pavitra
Updated on 25-Sep-2019 12:26:13

384 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statement −Given a square matrix of order n*n, we need to display elements of the matrix in Z form.Z form is traversing the matrix in the following steps −Traverse the first rowNow, traverse the second principal diagonalFinally, traverse the last row.We will take an input matrix here implicitly taken to demonstrate the flow of code.demostrateExample Live Demoarr = [[1, 2, 6, 9],    [1, 2, 3, 1],    [7, 1, 3, 5],    [1, 8, 7, 5]] n = len(arr[0]) i = 0 ... Read More

Update Column Data in MySQL and Remove Last String from Varchar

AmitDiwan
Updated on 25-Sep-2019 12:25:42

315 Views

Let us first create a table −mysql> create table DemoTable (    Download varchar(100) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('120 Gigabytes'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('190 Gigabytes'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('250 Gigabytes'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('1000 Gigabytes'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----------------+ ... Read More

Find Particular VARCHAR ID in MySQL from List of Values

AmitDiwan
Updated on 25-Sep-2019 12:23:55

266 Views

To get a particular varchar ID from a list, you can use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable (    Id varchar(255) ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('10, 100, 1000'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('101, 120, 2'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('3, 4, 5'); 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

Find the Sum of a Series in Python

Pavitra
Updated on 25-Sep-2019 12:21:44

3K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statement −Given an integer input n, we need to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!Here we are implementing for loop, therefore, we get O(n) as the time complexity.Here to reach the efficiency we calculate factorial within the same loop.Here we frame a sumofseries function as described below −Example Live Demodef sumOfSeries(num):    res = 0    fact = 1    for i in range(1, num+1):       fact *= i       res ... Read More

Populate NULL Columns in a MySQL Table and Set Values

AmitDiwan
Updated on 25-Sep-2019 12:21:18

674 Views

For this, you can use IS NULL property. Let us first create a table −mysql> create table DemoTable (    ProductPrice int,    ProductQuantity int,    TotalAmount int ); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ProductPrice, ProductQuantity) values(100, 2); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ProductPrice, ProductQuantity) values(500, 4); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(ProductPrice, ProductQuantity) values(1000, 10); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce ... Read More

Make a Pair of Columns Unique in MySQL

AmitDiwan
Updated on 25-Sep-2019 12:18:45

739 Views

To make a pair of columns unique, use UNIQUE with ALTER TABLE command. Following is the syntax −alter table yourTableName add unique yourUniqueName(yourColumnName1, yourColumnName2, ...N);Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentFirstName varchar(100),    StudentLastName varchar(100),    StudentAge int,    StudentPhoneNumber varchar(20) ); Query OK, 0 rows affected (0.81 sec)Following is the query to make a pair of unique columns in MySQL −mysql> alter table DemoTable add unique DemoTable_unique_StudentFirstName_StudentPhoneNumber(StudentFirstName, StudentPhoneNumber); Query OK, 0 rows affected (0.40 sec) Records: 0 Duplicates: 0 Warnings: 0Insert some records in the ... Read More

Find the Area of a Circle in Python

Pavitra
Updated on 25-Sep-2019 12:18:21

760 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statement −Given the radius of a circle, we need to find a circle.The area of a circle can simply be evaluated using the following formula.Area = Pi*r*rLet’s see the implementation below −Example Live Demodef findArea(r):    PI = 3.142    return PI * (r*r); # Driver method print("Area is %.6f" % findArea(5));OutputArea is 78.550000All variables and functions are declared in the global scope as shown in the figure below.ConclusionIn this article, we learned about the approach to find whether it is possible to make ... Read More

Tribonacci Word in C++

Arnab Chakraborty
Updated on 25-Sep-2019 12:17:14

221 Views

The Tribonacci Word is a sequence of digits. This is similar to the Fibonacci Words. Tribonacci Word is constructed by repeated concatenation of three previous stringsT(n) = T(n - 1) + T(n - 2) + T(n - 3)The first few strings to start, are {1, 12, 1213} So the next one will be 1213 + 12 + 1 = 1213121Algorithmtribonacci_word(n): Begin    first := 1, second := 12, third := 1213    print first, second, third    for i in range 3 to n, do       temp := third       third := third + second + ... Read More

Resolve Error 1064 42000 After Using Varchar Without Providing Size

AmitDiwan
Updated on 25-Sep-2019 12:15:53

1K+ Views

Let us first see when this situation can arise. Create a table and set column name with datatype but without the size −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar,    LastName varchar ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', LastName varchar )' at line 4You can correct the above error by providing the size for varchar data type like varchar(100). The same will fix the issue.Let’s fix it ... Read More

Advertisements