Write MySQL LIMIT in SQL Server

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

346 Views

You need to use TOP(1) in SQL Server. The syntax is as follows −SELECT TOP(1) *FROM yourTableName WHERE yourCondition;To understand the above syntax, let us create a table. The query to create a table is as follows −create table TopDemoInSQLServer (    Id int,    Name varchar(10) );The snapshot of creation of table is as follows −Insert some records in the table using insert command. The query is as follows −insert into TopDemoInSQLServer values(10, 'John'); insert into TopDemoInSQLServer values(14, 'Carol'); insert into TopDemoInSQLServer values(1, 'Sam'); insert into TopDemoInSQLServer values(11, 'Bob'); insert into TopDemoInSQLServer values(18, 'David'); insert into TopDemoInSQLServer values(20, 'Sam');The ... Read More

Get Android Device Name Programmatically

Nitya Raut
Updated on 30-Jul-2019 22:30:25

3K+ Views

This example demonstrate about How to get programmatically android device name.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken text view to show device name.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.Manifest; import android.app.ProgressDialog; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.webkit.CookieManager; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import ... Read More

Apply XSL Transformation on an XML Document

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

512 Views

The tag applies an XSL transformation on an XML document.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultdocSource XML document for the XSLT transformationNoBodydocSystemIdURI of the original XML documentNoNonexsltXSLT stylesheet providing transformation instructionsYesNonexsltSystemIdURI of the original XSLT documentNoNoneresultResult object to accept the transformation's resultNoPrint to pagevarVariable that is set to the transformed XML documentNoPrint to pagescopeScope of the variable to expose the transformation's resultNoNoneExampleConsider the following XSLT stylesheet style.xsl −                                                                                                                                                                                                                                                                     Now consider the following JSP file −           JSTL x:transform Tags               Books Info:                                                 Padam History                 ZARA                 100                                             Great Mistry                 NUHA                 2000                                 You will receive the following result −Books InfoPadam HistoryZARA100Great MistryNUHA2000

ListIterator Method of CopyOnWriteArrayList in Java

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

147 Views

The listIterator() method CopyOnWriteArrayList class returns a list iterator over the elements in this list, beginning at the specified position in the list.The syntax is as followspublic ListIterator listIterator(int index)Here, index is the index of the first element to be returned from the list iterator.To work with CopyOnWriteArrayList class, you need to import the following packageimport java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class listIterator() method in Java. We have set the index as 3, therefore, the list would be iterated from index 3Example Live Demoimport java.util.Iterator; import java.util.ListIterator; import java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] ... Read More

Find Document by Non-Existence of a Field in MongoDB

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

106 Views

To find a document by the non-existence of a field in MongoDB, the syntax is as follows −db.yourCollectionName.find({ "yourFieldName" : { "$exists" : false } }).pretty();To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.findDocumentNonExistenceFieldDemo.insertOne({"StudentName":"John", "StudentAge":25}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a5c629064dcd4a68b70e8") } > db.findDocumentNonExistenceFieldDemo.insertOne({"StudentName":"David", "StudentAge":26, "StudentMathMarks":78}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a5c809064dcd4a68b70e9") }Display all documents from a collection with the help of find() method. The query is as follows −> db.findDocumentNonExistenceFieldDemo.find().pretty();The following is the output −{ ... Read More

unordered_multimap::reserve Function in C++ STL

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

153 Views

The unordered_multimap reserve() function in C++ STL sets the number of buckets in the container to the most appropriate number so that it contains at least n elements.If n is greater than the current numbers of bucket multiplied by the max_load_factor, the container’s number of buckets is increased and a rehash is forced.Reserve () returns nothing and take n as a parameter which specifies the minimum number of elements as per requested minimum capacity.AlgorithmBegin    Declare the vector m.    m.reserve(6) = the size is reserved for the bucket to contain minimum number of one elements.    Insert the key ... Read More

Is It Legal to Recurse into Main in C++?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

131 Views

In C or C++, the main function is like other functions. So we can use the functionalities that are present in some other functions, also in the main function.In the following program, we will see how the main() is using recursively to print some numbers in reverse order.Example Code#include using namespace std; int main () {    static int x = 10;    cout

MongoDB Order By Two Fields Sum

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

474 Views

To order by two fields sum, you can use the aggregate framework. Let us first create a collection with documents> db.orderByTwoFieldsDemo.insertOne({"Value1":10, "Value2":35}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca285576304881c5ce84baa") } > db.orderByTwoFieldsDemo.insertOne({"Value1":12, "Value2":5}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca2855f6304881c5ce84bab") } > db.orderByTwoFieldsDemo.insertOne({"Value1":55, "Value2":65}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca285686304881c5ce84bac") }Following is the query to display all documents from a collection with the help of find() method> db.orderByTwoFieldsDemo.find().pretty();This will produce the following output{    "_id" : ObjectId("5ca285576304881c5ce84baa"),    "Value1" : 10,    "Value2" : 35 } {    "_id" : ObjectId("5ca2855f6304881c5ce84bab"),    "Value1" ... Read More

Convert Long ArrayList to Long Array in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

4K+ Views

Firstly, declare a Long array list and add some elements to it:ArrayList < Long > arrList = new ArrayList < Long > (); arrList.add(100000 L); arrList.add(200000 L); arrList.add(300000 L); arrList.add(400000 L); arrList.add(500000 L);Now, set the same size for the newly created long array:final long[] arr = new long[arrList.size()]; int index = 0;Each and every element of the Long array list is assigned to the long array:for (final Long value : arrList) {    arr[index++] = value; }Exampleimport java.util.ArrayList; public class Demo {    public static void main(String[] args) {       ArrayList

Count Null Values in MySQL

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

1K+ Views

To count null values in MySQL, you can use CASE statement. Let us first see an example and create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(20) ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName) values('John'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(FirstName) values(null); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(FirstName) values(''); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(FirstName) values('Larry'); Query OK, 1 row affected (0.17 ... Read More

Advertisements