Articles on Trending Technologies

Technical articles with clear explanations and examples

Sum columns corresponding values according to similar dates in MySQL?

AmitDiwan
AmitDiwan
Updated on 11-Dec-2019 246 Views

For this, use aggregate function SUM() along with GROUP BY. Let us first create a table −mysql> create table DemoTable1522    -> (    -> ProductPurchaseDate date,    -> NumberOfProduct int    -> ); Query OK, 0 rows affected (1.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1522 values('2019-01-21', 45); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1522 values('2018-12-31', 78); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1522 values('2019-01-21', 67); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1522 values('2019-03-01', 56); Query OK, 1 row affected (0.19 ...

Read More

Convert Class in C#

AmitDiwan
AmitDiwan
Updated on 11-Dec-2019 773 Views

The Convert Class has methods to convert a base data type to another base data type. Let us see some examples −The Convert.ToBoolean() method in C# is used to convert a specified value to an equivalent Boolean value.SyntaxFollowing is the syntax −public static bool ToBoolean (string val, IFormatProvider provider);Above, Val is a string that contains the value of either TrueString or FalseString, whereas the provider is an object that supplies culture-specific formatting information.ExampleLet us now see an example to implement the Convert.ToBoolean() method − Live Demousing System; using System.Globalization; public class Demo {    public static void Main(){       ...

Read More

Update a column in MySQL and remove the trailing underscore values

AmitDiwan
AmitDiwan
Updated on 11-Dec-2019 591 Views

To remove the trailing values, use TRIM() as in the below update syntax −update yourTableName set yourColumnName=trim(trailing '_' from yourColumnName);Let us first create a table −mysql> create table DemoTable1521    -> (    -> StudentCode varchar(20)    -> ); Query OK, 0 rows affected (1.33 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1521 values('345_'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1521 values('12345'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable1521 values('9084_'); Query OK, 1 row affected (1.29 sec)Display all records from the table using select statement −mysql> select ...

Read More

Char Struct in C#

AmitDiwan
AmitDiwan
Updated on 11-Dec-2019 443 Views

The Char Struct in C# represents a character as a UTF-16 code unit. Here are some of the methods −MethodDescriptionConvertToUtf32(Char, Char)Converts the value of a UTF-16 encoded surrogate pair into a Unicode code point.ConvertToUtf32(String, Int32)Converts the value of a UTF-16 encoded character or surrogate pair at a specified position in a string into a Unicode code point.Equals(Char)Returns a value that indicates whether this instance is equal to the specified Char object.Equals(Object)Returns a value that indicates whether this instance is equal to a specified object.GetHashCode()Returns the hash code for this instance.GetNumericValue(Char)Converts the specified numeric Unicode character to a double-precision floating-point number.IsDigit(String, ...

Read More

How do I select data from one table only where column values from that table match the column values of another table in MySQL?

AmitDiwan
AmitDiwan
Updated on 11-Dec-2019 4K+ Views

For this, you can use subquery along with EXISTS. Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int,    -> SubjectName varchar(20)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(111, 'MySQL'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1 values(112, 'MongoDB'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1 values(113, 'Java'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1 values(114, 'C'); Query OK, 1 row affected (0.27 sec) ...

Read More

MySQL query to select rows one batch at a time

AmitDiwan
AmitDiwan
Updated on 11-Dec-2019 3K+ Views

For this, you can use the concept of LIMIT and OFFSET. Let us first create a table −mysql> create table DemoTable1514    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1514(FirstName) values('Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1514(FirstName) values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1514(FirstName) values('Sam'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1514(FirstName) values('Mike'); Query OK, 1 row ...

Read More

When inserting a new row, should I include the columns that are null in the MySQL query?

AmitDiwan
AmitDiwan
Updated on 11-Dec-2019 159 Views

If you do not specify the column list in insert statement then you can use below syntax −insert into yourTableName values(NULL, yourValue, NULL, NULL, .....N);Let us first create a table −mysql> create table DemoTable1513    -> (    -> StudentId int,    -> StudentName varchar(20) ,    -> StudentAge int,    -> StudentCountryName varchar(20)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1513 values(NULL, 'Chris Brown', NULL, NULL); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1513 values(101, NULL, NULL, NULL); Query OK, 1 row ...

Read More

How do I detect if the ON UPDATE event fired with query in MySQL?

AmitDiwan
AmitDiwan
Updated on 11-Dec-2019 240 Views

You can detect with the help of row_count(). If the row_count() returns 1 that means it is a new record. If it returns 2, that means the ON UPDATE event is fired with query. Following is the syntax −select row_count();Let us first create a table −mysql> create table DemoTable1512    -> (    -> Value int ,    -> UNIQUE(Value)    -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1512 values(90) on duplicate key update Value=Value+10; Query OK, 1 row affected (0.09 sec)Now you can check the on ...

Read More

How to prevent MySQL GROUP BY from collapsing NULL values into a single row?

AmitDiwan
AmitDiwan
Updated on 11-Dec-2019 1K+ Views

Fir this, you can use IFNULL() along with ORDER BY clause. Let us first create a table table −mysql> create table DemoTable1511    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (1.97 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1511(FirstName) values('John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1511(FirstName) values('Robert'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable1511(FirstName) values('Mike'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1511(FirstName) values('Robert'); Query OK, 1 ...

Read More

MySQL update datetime column values and add 10 years 3 months 22 days and 10 hours, 30 minutes to existing data?

AmitDiwan
AmitDiwan
Updated on 11-Dec-2019 536 Views

For this, you can use INTERVAL in MySQL. Let us first create a table −mysql> create table DemoTable1509    -> (    -> ArrivalTime datetime    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1509 values('2018-01-21 10:20:30'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1509 values('2019-04-01 11:00:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1509 values('2015-12-12 05:45:20'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select * from DemoTable1509;This will produce the following output ...

Read More
Showing 52451–52460 of 61,248 articles
Advertisements