Generate Row Count and Serial Number of Records in MySQL Query

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

5K+ Views

To generate serial number i.e. row count in MySQL query, use the following syntax.SELECT @yourVariableName − = @yourVariableName+1 anyAliasName,    yourColumnName1, yourColumnName2, yourColumnName3, ....N from yourTableName ,    (select @yourVariableName − = 0) as yourVariableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table tblStudentInformation    -> (    -> StudentName varchar(20),    -> StudentAge int,    -> StudentMathMarks int    -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into tblStudentInformation values('Carol', ... Read More

Trees Used for Furniture and Long-Lasting Wood Types

Ridhi Arora
Updated on 30-Jul-2019 22:30:24

4K+ Views

There are various trees used for furniture, depending on their desired characteristics. For example, in order to get the durable material, some particular type of wood is used, while in order to get a luster and shine in the product, a different wood is used.Different Trees Used for FurnitureOak Trees: These trees are famous for hard-grade wood red, or white color. Its property of absorbing any color is evident from the fact that it has large annual rings inside.Maple Trees: The good thing about Maple is that it is less expensive than most of the alternatives of the same hardness ... Read More

Is Null a Literal in Java?

Arushi
Updated on 30-Jul-2019 22:30:24

840 Views

The null in Java is a literal of the null type. It cannot be cast to a primitive type such as int. float etc. but can be cast to a reference type. Also, null does not have the value 0 necessarily.A program that demonstrates null in Java is given as follows:Example Live Demopublic class Demo {    public static void main(String args[]) {       String str = null;       System.out.println("Value of str is: " + str);    } }OutputValue of str is: nullNow let us understand the above program.In the main() method, the String str is initialized ... Read More

The extends Keyword in Java

Vikyath Ram
Updated on 30-Jul-2019 22:30:24

5K+ Views

An object can acquire the properties and behaviour of another object using Inheritance. In Java, the extends keyword is used to indicate that a new class is derived from the base class using inheritance. So basically, extends keyword is used to extend the functionality of the class.A program that demonstrates the extends keyword in Java is given as follows:Example Live Democlass A {    int a = 9; } class B extends A {    int b = 4; } public class Demo {    public static void main(String args[]) {       B obj = new B();     ... Read More

MySQL CONCAT to Create Column Names for Queries

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

840 Views

To create column names to be used in a query, you need to use a user-defined variable with the set command. The syntax is as follows −SET @anyVariableName := (    SELECT CONCAT    (       "SELECT",    GROUP_CONCAT(CONCAT(" 1 as ", COLUMN_NAME) SEPARATOR ', '), " FROM DUAL")    FROM INFORMATION_SCHEMA_COLUMNS    WHERE TABLE_NAME= ‘yourTableName’ );Now prepare the statement using the PREPARE command. The syntax is as follows −PREPARE anyVariableName from @anyVariableName;Execute statement using EXECUTE command. The syntax is as follows −EXECUTE anyVariableName;Deallocate the prepared statement using DEALLOCATE command. The syntax is as follows −DEALLOCATE PREPARE anyVariableName; ... Read More

Copy Array from Specified Source Array in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

190 Views

Use arraycopy() method in Java to copy an array from the specified source array.Here, we have two arrays −int arr1[] = { 10, 20, 30, 40}; int arr2[] = { 3, 7, 20, 30};Now, we will use the arraycopy() method to copy the first two elements of the 1st array to the 2nd array −System.arraycopy(arr1, 0, arr2, 2, 2);The following is an example −Example Live Demoimport java.lang.*; public class Demo { public static void main(String[] args) { int arr1[] = { 10, 20, 30, 40}; int arr2[] = { 3, 7, 20, 30}; System.arraycopy(arr1, 0, arr2, 2, 2); System.out.print("New Array = "); System.out.print(arr2[0] + " "); System.out.print(arr2[1] + " "); System.out.print(arr2[2] + " "); System.out.print(arr2[3] + " "); } }OutputNew Array = 3 7 10 20

Display Three-Letter Month Value with SimpleDateFormat in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

4K+ Views

Using the SimpleDateFormat(“MMM”) to display three-letter month −Format f = new SimpleDateFormat("MMM"); String strMonth = f.format(new Date()); System.out.println("Month (Three-letter format) = "+strMonth);Since, we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date −import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo {    public static void main(String[] args) throws Exception {       // displaying current date and time       Calendar cal = Calendar.getInstance();       SimpleDateFormat simpleformat = new SimpleDateFormat("E, ... Read More

Query Between Two Dates in MySQL

Anvi Jain
Updated on 30-Jul-2019 22:30:24

18K+ Views

You can query between dates with the help of BETWEEN statement. The syntax is as follows −select *from yourTableName where yourColumnName between ‘yourStartingDate’ and curdate().Use curdate() or now(), both these functions will work. To understand the above syntax, let us create a table −mysql> create table BetweenDateDemo −> ( −> StartDate datetime −> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table with the help of the following query −mysql> insert into BetweenDateDemo values(date_add(now(), interval -1 year)); Query OK, 1 row affected (0.11 sec) mysql> insert ... Read More

ElementTree XML API in Python

Chandu yadav
Updated on 30-Jul-2019 22:30:24

12K+ Views

The Extensible Markup Language (XML) is a markup language much like HTML. It is a portable and it is useful for handling small to medium amounts of data without using any SQL database.Python's standard library contains xml package. This package has ElementTree module. This is a simple and lightweight XML processor API.XML is a tree like hierarchical data format. The 'ElementTree' in this module treats the whole XML document as a tree. the 'Element' class represents a single node in this tree. Reading and writing operations on XML files are done on the ElementTree level. Interactions with a single XML ... Read More

Remove Trailing Zeros in Decimal Value in MySQL

George John
Updated on 30-Jul-2019 22:30:24

11K+ Views

You can remove trailing zeros using TRIM() function. The syntax is as follows.SELECT TRIM(yourColumnName)+0 FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table removeTrailingZeroInDecimal    -> (    -> Id int not null auto_increment,    -> Amount decimal(5, 2),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (1.01 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into removeTrailingZeroInDecimal(Amount) values(405.50); Query OK, 1 row affected (0.22 sec) mysql> insert into removeTrailingZeroInDecimal(Amount) values(23.05); Query OK, ... Read More

Advertisements