Fetch MySQL Rows Posted Before the Last 3 Days

AmitDiwan
Updated on 16-Dec-2019 06:25:24

171 Views

Let’s say the current date is −'2019-10-20We will first see an example and create a table −mysql> create table DemoTable1582    -> (    -> PostedDate datetime    -> ); Query OK, 0 rows affected (13.36 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1582 values('2019-01-21 12:34:40'); Query OK, 1 row affected (1.06 sec) mysql> insert into DemoTable1582 values('2019-10-15 11:00:00'); Query OK, 1 row affected (0.87 sec) mysql> insert into DemoTable1582 values('2019-10-25 1:10:00'); Query OK, 1 row affected (1.14 sec)Display all records from the table using select statement −mysql> select * from DemoTable1582;This will produce the ... Read More

Get All Elements of a List Matching Predicate in C#

AmitDiwan
Updated on 16-Dec-2019 06:22:50

642 Views

To get all elements of a List that match the conditions specified by the predicate, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo {    private static bool demo(int i) {       return ((i % 3) == 0);    }    public static void Main(String[] args) {       List list = new List();       list.Add(9);       list.Add(15);       list.Add(20);       list.Add(40);       list.Add(50);       list.Add(60);       Console.WriteLine("List elements...");       foreach (int i in list) {   ... Read More

Ensure Unique Rows in MySQL

AmitDiwan
Updated on 16-Dec-2019 06:19:54

458 Views

To ensure that MySQL rows are unique, you need to use UNIQUE constraint. Let us first create a table −mysql> create table DemoTable1580    -> (    -> id int,    -> Name varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (0.73 sec)Here is the query to create unique constraints to ensure MySQL rows are unique −mysql> alter table DemoTable1580 add unique index(id, Name, Age); Query OK, 0 rows affected (0.45 sec) Records: 0  Duplicates: 0  Warnings: 0Insert some records in the table using insert command −mysql> insert into DemoTable1580 values(101, 'Chris', 21); Query OK, ... Read More

Get Hash Code for Specified Key of Hashtable in C#

AmitDiwan
Updated on 16-Dec-2019 06:19:21

269 Views

To get hash code for the specified key of a Hashtable, the code is as follows −Example Live Demousing System; using System.Collections; public class HashCode : Hashtable {    public static void Main(string[] args) {       HashCode hash = new HashCode();       hash.Add("A", "Jacob");       hash.Add("B", "Mark");       hash.Add("C", "Tom");       hash.Add("D", "Nathan");       hash.Add("E", "Tim");       hash.Add("F", "John");       hash.Add("G", "Gary");       Console.WriteLine("Key and Value pairs...");       foreach(DictionaryEntry entry in hash) {          Console.WriteLine("{0} and {1} ", ... Read More

Select Last Three Rows of a Table in Ascending Order with MySQL

AmitDiwan
Updated on 16-Dec-2019 06:15:52

690 Views

To select the last three rows in ascending order, use ORDER BY DESC LIMIT as in the below syntax −select * from (select * from yourTableName order by yourColumnName desc limit 3) anyAliasName order by yourColumnName ;Let us first create a table −mysql> create table DemoTable1579    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1579(Name) values('Robert'); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable1579(Name) values('Bob'); Query OK, 1 ... Read More

Get Synchronized Access to ListDictionary in C#

AmitDiwan
Updated on 16-Dec-2019 06:15:05

175 Views

To get synchronize access to the ListDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       ListDictionary dict = new ListDictionary();       dict.Add("1", "SUV");       dict.Add("2", "Sedan");       dict.Add("3", "Utility Vehicle");       dict.Add("4", "Compact Car");       dict.Add("5", "SUV");       dict.Add("6", "Sedan");       dict.Add("7", "Utility Vehicle");       dict.Add("8", "Compact Car");       dict.Add("9", "Crossover");       dict.Add("10", "Electric Car");       Console.WriteLine("ListDictionary elements...");       ... Read More

Select and Insert in Two Tables with a Single Query in MySQL

AmitDiwan
Updated on 16-Dec-2019 06:11:45

388 Views

Here is the query to create first table.mysql> create table DemoTable1    -> (    -> StudentName varchar(20),    -> StudentMarks int    -> ); Query OK, 0 rows affected (0.67 sec)To understand the above concept, let us create second table.mysql> create table DemoTable2    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2 values('Chris'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable2;This will produce the following output −+-------+ ... Read More

Easiest Way to Get Number of Rows in a MySQL Table

AmitDiwan
Updated on 16-Dec-2019 06:10:14

214 Views

The easiest way to get number of rows, use aggregate function COUNT(*). Let us first create a table −mysql> create table DemoTable1575    -> (    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (1.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1575 values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1575 values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1575 values('Adam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1575 values('Robert'); Query OK, 1 row affected (0.15 sec)Display all records from the table ... Read More

Replace Special Characters in MySQL Column Value

AmitDiwan
Updated on 16-Dec-2019 06:08:49

1K+ Views

Let us first create a table −mysql> create table DemoTable1574    -> (    -> StudentCode varchar(20)    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1574 values('111_Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1574 values('______'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1574 values('David_12345'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1574 values('______'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable1574;This will produce the following ... Read More

Retrieve Table Names from a Database in MySQL

AmitDiwan
Updated on 16-Dec-2019 06:07:34

352 Views

To retrieve table names from a database in MySQL, the syntax is as follows −show tables from yourDatabaseName;Let us implement the above query in order to retrieve table names from a database in MySQL −mysql> show tables from hb_student_tracker;This will produce the following output −+------------------------------+ | Tables_in_hb_student_tracker | +------------------------------+ | demotable192                 | | demotable193                 | | demotable194                 | | demotable195                 | | demotable196           ... Read More

Advertisements