Implement COUNT as Variable in MySQL to Display Record Count

AmitDiwan
Updated on 21-Aug-2019 11:43:02

1K+ Views

The alias name can be used as a variable name in MySQL as shown in the below syntax −select count(*) AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable695 (    FirstName varchar(100) ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command −mysql> insert into DemoTable695 values('Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable695 values('Robert'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable695 values('David'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable695 values('Mike'); Query OK, 1 row affected (0.16 ... Read More

Get First and Last Record of Table in MySQL

AmitDiwan
Updated on 21-Aug-2019 11:41:46

18K+ Views

To get the first and last record, use UNION. LIMIT is also used to get the number of records you want.Let us first create a table −mysql> create table DemoTable694 (    EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    EmployeeName varchar(100),    EmployeeSalary int ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable694(EmployeeName, EmployeeSalary) values('Chris', 457647); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable694(EmployeeName, EmployeeSalary) values('Robert', 90883); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable694(EmployeeName, EmployeeSalary) values('David', 123532); Query OK, 1 row ... Read More

Use WHEN as Column Name in CREATE TABLE Statement

AmitDiwan
Updated on 21-Aug-2019 11:39:49

120 Views

Before beginning, let us try to set ‘when’ as column name while using CREATE TABLE statement −mysql> create table DemoTable693(    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(100),    When datetime );This will produce the following output. An error would be visible:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'When datetime at line 5You need to wrap the reserved word using backticks, for example, `when`. Let us first create a table and implement the same:mysql> create table ... Read More

Get a List of MySQL Databases and Version

AmitDiwan
Updated on 21-Aug-2019 11:36:21

162 Views

To get a list of MySQL databases, following is the syntax -show databases;To get the server version, you can use the below syntax -select version();Let us implement the above syntax to get a list of MySQL databases and version -mysql> show databases;This will produce the following output displaying all the databases -+---------------------------+ | Database                  | +---------------------------+ | bothinnodbandmyisam       | | business                  | | commandline               | | customer-tracker          | | customer_tracker_database ... Read More

Group By Date Regardless of Time in MySQL

AmitDiwan
Updated on 21-Aug-2019 11:33:06

500 Views

When you have identical dates in a table with different time values for each, you can group them easily with GROUP BY DATE.Let us first create a table -mysql> create table DemoTable692 (DueDatetime datetime); Query OK, 0 rows affected (0.97 sec)Insert some records in the table using insert command:mysql> insert into DemoTable692 values('2019-07-21 10:20:00'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable692 values('2019-06-11 11:00:10'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable692 values('2019-07-21 11:00:10'); Query OK, 1 row affected (1.97 sec) mysql> insert into DemoTable692 values('2019-07-21 12:10:10'); Query OK, 1 row affected (0.18 sec)Display ... Read More

Add Buttons Programmatically into a Layout in Android

Azhar
Updated on 21-Aug-2019 11:21:09

2K+ Views

This example demonstrates how do I programmatically add buttons into a layout one by one several lines in android.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. Step 3 − Add the following code to src/MainActivity.javapackage app.com.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Button; import android.widget.LinearLayout; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       LinearLayout layout = new ... Read More

Create Tab Layout in Android App

Azhar
Updated on 21-Aug-2019 10:54:21

5K+ Views

This example demonstrates how do I create a Tab Layout in android app.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 dependency to create a tab layout −implementation 'com.android.support:design:28.0.0'Step 3 − Add the following code to res/layout/activity_main.xml.             Step 4 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.view.ViewPager; public class MainActivity extends AppCompatActivity {    TabLayout tabLayout;    ViewPager viewPager;    @Override    protected void onCreate(Bundle ... Read More

Centre Align Action Bar Title in Android

Azhar
Updated on 21-Aug-2019 08:34:07

4K+ Views

This example demonstrates how do I centre align action bar title in android.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.     Step 3 − Add the following code to src/MainActivity.javaimport android.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);       getSupportActionBar().setCustomView(R.layout.activity_main);    } }Step 4 − Add the ... Read More

Create Custom Alert Dialogs in an Android App

Azhar
Updated on 21-Aug-2019 08:32:31

227 Views

This example demonstrates how do I make a specific text on TextView bold in android.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.         Step 3 – Create a layout resourse file and add the following code in customdialog.xml             Step 3 − Add the following code to src/MainActivity.javaimport android.app.Dialog; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity ... Read More

Change App Language Based on User Selection in Android

Azhar
Updated on 21-Aug-2019 08:30:37

1K+ Views

This example demonstrates how do I change app language when user selects language.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.         Step 3 − Add the following code to src/MainActivity.javaimport android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.Toast; import java.util.ArrayList; import java.util.List; import java.util.Locale; public class MainActivity extends AppCompatActivity {    Spinner spinner;    Locale locale;    String ... Read More

Advertisements