Order By RAND and Keep Them Grouped in MySQL

AmitDiwan
Updated on 11-Dec-2019 11:48:38

276 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentMarks int    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command. We have also inserted duplicate records −mysql> insert into DemoTable(StudentMarks) values(98); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(StudentMarks) values(98); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(StudentMarks) values(78); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(StudentMarks) values(78); Query OK, 1 row affected (0.29 sec) mysql> insert ... Read More

Insert Data from One Table to Another in MySQL

AmitDiwan
Updated on 11-Dec-2019 11:44:49

1K+ Views

To insert data from one table to another, use the INSERT INTO SELECT statement. Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int,    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(101, 'Adam'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1 values(102, 'John'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+------+-----------+ | Id   ... Read More

Select Date from MySQL and Format to Text

AmitDiwan
Updated on 11-Dec-2019 11:42:55

207 Views

To select date and format, use SELECT DATE_FORMAT(). Following is the syntax −Syntaxselect date_format(yourColumnName, '%e %b %y') from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> DueDate date    -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-11'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-12-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-09-15'); Query OK, 1 row affected (0.07 sec)Display all records from the table using select statement −mysql> select *from ... Read More

Group MySQL Rows in an Array by Column Value

AmitDiwan
Updated on 11-Dec-2019 11:40:22

3K+ Views

To group rows in an array, use GROUP_CONCAT() along with the ORDER BY clause. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(101, 'John'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(102, 'Bob'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(101, 'David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(101, 'Adam'); Query OK, ... Read More

Get Hashcode for Current UInt32 Instance in C#

AmitDiwan
Updated on 11-Dec-2019 11:32:46

134 Views

To get the HashCode for the current UInt32 instance, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       uint val1 = 100;       uint val2 = UInt16.MinValue;       Console.WriteLine("HashCode for val1 = "+val1.GetHashCode());       Console.WriteLine("HashCode for val2 = "+val2.GetHashCode());    } }OutputThis will produce the following output −HashCode for val1 = 100 HashCode for val2 = 0ExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main() {       uint val1 = 50;   ... Read More

Using Foreach Loop in Arrays in C#

AmitDiwan
Updated on 11-Dec-2019 11:30:45

267 Views

Let us see an example to use foreach loop in arrays −Example Live Demousing System; public class Demo {    public static void Main() {       string[] products = new string[] { "Electronics", "Accessories", "Clothing", "Toys", "Clothing", "Furniture" };       Console.WriteLine("Products list...");       foreach(string s in products) {          Console.WriteLine(s);       }       Console.WriteLine("Is the products Accessories in the array? = {0}", Array.Exists(products, ele => ele == "Accessories"));       Console.WriteLine("Is the products Stationery in the array? = {0}", Array.Exists(products, ele => ele == "Stationery"));     ... Read More

Get Angle Whose Sine is Float Value Argument in C#

AmitDiwan
Updated on 11-Dec-2019 11:26:30

161 Views

To get the angle whose sine is float value argument, the code is as follows −Exampleusing System; public class Demo {    public static void Main() {       float val1 = 0.1f;       float val2 = 8.9f;       Console.WriteLine("Angle (val1) = "+(MathF.Asin(val1)));       Console.WriteLine("Angle (val2) = "+(MathF.Asin(val2)));    } }OutputThis will produce the following output −Angle (val1) = 0.1001674 Angle (val2) = NaNExampleLet us see another example −using System; public class Demo {    public static void Main() {       float val1 = 1.2f;       float val2 = ... Read More

Get Hyperbolic Arc Cosine of a Floating Point Value in C#

AmitDiwan
Updated on 11-Dec-2019 11:10:22

139 Views

To get the hyperbolic arc-cosine of a floating-point value, the code is as follows −Exampleusing System; public class Demo {    public static void Main() {       float val1 = 0.1f;       float val2 = 0.9f;       Console.WriteLine("Angle (val1) = "+(MathF.Acosh(val1)));                                 Console.WriteLine("Angle (val2) = "+(MathF.Acosh(val2)));    } }OutputThis will produce the following output −Angle (val1) = NaN Angle (val2) = NaNExampleLet us see another example −using System; public class Demo {    public static void Main() {       float val1 = 5.1f;       float val2 = 8.9f;       Console.WriteLine("Angle (val1) = "+(MathF.Acosh(val1)));       Console.WriteLine("Angle (val2) = "+(MathF.Acosh(val2)));    } }OutputThis will produce the following output −Angle (val1) = 2.312634 Angle (val2) = 2.876027

Check Surrogate Code for Character in C#

AmitDiwan
Updated on 11-Dec-2019 11:07:06

229 Views

To check whether the specified character has a surrogate code, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       string str = new String(new char[] { 'k', 'm', 'g', 't', '\uD800' });       bool res = Char.IsSurrogate(str, 4);       if (res)          Console.WriteLine("Contains Surrogate value!");       else          Console.WriteLine("Does not contain Surrogate value!");    } }OutputThis will produce the following output −Contains Surrogate value!ExampleLet us see another example − Live Demousing System; public class Demo {   ... Read More

Get Synchronized Access to StringDictionary in C#

AmitDiwan
Updated on 11-Dec-2019 11:02:44

102 Views

To get synchronize access to the StringDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       StringDictionary strDict = new StringDictionary ();       strDict.Add("A", "Books");       strDict.Add("B", "Electronics");       strDict.Add("C", "Appliances");       strDict.Add("D", "Pet Supplies");       strDict.Add("E", "Clothing");       strDict.Add("F", "Footwear");       Console.WriteLine("StringDictionary key-value pairs...");       foreach(DictionaryEntry de in strDict) {          Console.WriteLine(de.Key + " " + de.Value);       }       Console.WriteLine("Value ... Read More

Advertisements