DEV Community

Cover image for One Commit at a Time ! Series - 7
Annapoorani Kadhiravan
Annapoorani Kadhiravan

Posted on

One Commit at a Time ! Series - 7

JAVA

# Create objects inside the same class

class Lamp {

  // stores the value for light
  // true if light is on
  // false if light is off
  boolean isOn;

  // method to turn on the light
  void turnOn() {
    isOn = true;
    System.out.println("Light on? " + isOn);

  }

  public static void main(String[] args) {

    // create an object of Lamp
    Lamp led = new Lamp();

    // access method using object
    led.turnOn();
  }
}

OUTPUT :
Light on? true

Enter fullscreen mode Exit fullscreen mode

SQL

The SELECT DISTINCT statement is used to return only distinct (unique) values.

In a table, a column may contain several duplicate values - and sometimes you want to list only the unique values.

SELECT DISTINCT Syntax
SELECT DISTINCT column1, column2, ...
FROM table_name;

SELECT DISTINCT Country FROM Customers;
Enter fullscreen mode Exit fullscreen mode

Count Distinct Values
By using the COUNT() function with the DISTINCT keyword, we can count the number of unique countries.

SELECT COUNT(DISTINCT Country) FROM Customers;
Enter fullscreen mode Exit fullscreen mode

References :
https://www.w3schools.com/sql/sql_distinct.asp
https://www.programiz.com/java-programming/class-objects

Top comments (0)