Skip to main content

MySQL Notes

MySQL Notes 


show databases;

use world;

show tables;

desc city;

/to show all content of table city/

select * from city limit 10;

/to show name,district,population/

select Name,District,Population from city limit 10;

/order by helps to sort records in ascending/ 

select Name,Population from city order by Name asc limit 10;

/order by in descending order for name/

select Name,Population from city order by Name desc limit 10;

select Name,Population from city order by Population desc limit 10;

select Name,Population from city order by Population asc;

/order by in multiple column/

select Name,Population from city order by Name asc,Population desc;

/where clause/

/*

MySQL Logical Operators

(i) AND

(ii) OR

(iii) BETWEEN

(IV) NOT BETWEEN

(V) LIKE

(VI) NOT

(VII) IS NULL

(VIII) IN

(IX) NOT IN 

(X) IS NOT NULL

(XI) < > <= >= != == (RELATIONAL OPERATORS)

*/

/*

flow of writing mysql

from -> where -> select -> order by

*/

select * from city limit 10;

/display the districts of India/

select District from city where CountryCode="IND";

show tables;

desc country;

select * from country;

select Name,Population,LifeExpectancy from country limit 10;

/*to display name of countries where Population is more 100000 and life expectancy is

more 80*/

select Name,Population,LifeExpectancy 

from country 

where Population>=100000 and LifeExpectancy>=80;

/*To display the name of countries where Population is less than 100000 or 

LifeExpectancy is more than 80

*/

select Name,Population,LifeExpectancy 

from country 

where Population<=100000 or LifeExpectancy>=80;

/*

to display the name of countries where population is between 10000 and 50000

*/

select Name,Population 

from country 

where Population 

between 10000 and 50000 

order by Name asc;

/to display the names of the coutries which are not in Asia,Afria and Europe/

select Name,Continent

from country

where 

Continent not in ("Asia","Africa","Europe");

/to display all the countries whicha are not in the Africa continent/

select Name,Continent

from country

where (not Continent="Africa");

/to display all the names of country which begins with alphabet D/

select Name 

from country

where Name Like 'D%';

/to display all the names of countries which begins A and ends with N/

select Name

from country

where Name Like 'A%N';

/to display the names of countries which has "and" word between the name/

select Name

from country

where Name Like '%and%';

/to display the independence year is blank/

select Name,IndepYear

from country

where IndepYear is null;

/*to display country names where indepedence year is not blank/

select Name,IndepYear

from country

where IndepYear is not null

order by IndepYear desc;

/to display the names of continent without any duplications/ 

select distinct Continent

from Country;

/to distinct on multiple columns/ 

select distinct Name,Continent

from Country;

/count() counts the number of rows in a table/

select count(*) from Country;

/count the number of continent/

select count(distinct continent) as "Number of continents"

from country;

/display the lowest population/

select min(Population)

from country;

/display the highest population/

select max(Population)

from country;

/display the total population/

select sum(Population)

from country;

/display the average population/

select avg(Population)

from country;

Popular posts from this blog

Panagram ISC 2025 Specimen Practical Paper

import java.util.*; class panagram //ISC 2025 Practical Question {     //str for storing the sentence     String str;     panagram()     {         str="";     }     void accept()     {         Scanner sc=new Scanner(System.in);         System.out.println("Enter a sentence:");         str=sc.nextLine();     }     void panagramcheck()     {         int letters[]=new int[26];          StringTokenizer st=new StringTokenizer(str);         while(st.hasMoreTokens())         {             String w = st.nextToken().toUpperCase();             for(int i=65;i<=90;i++)             {                 for(int j=...

Program in Java: ISC Program CellPhone Keystrokes

import java.util.Scanner; public class Keypad {     public static void main(String args[])     {         //Array to hold keystrokes for each letter         int keys[] = new int[26];         //intialise         keys['A'-'A']=1; //A         keys['B'-'A']=2; //B         keys['C'-'A']=3; //C         keys['D'-'A']=1; //D         keys['E'-'A']=2; //E         keys['F'-'A']=3; //F         keys['G'-'A']=1; //G         keys['H'-'A']=2; //H         keys['I'-'A']=3; //I         keys['J'-'A']=1; //J         keys['K'-'A']=2; //K         keys['L'-'A']=3; //L         keys['M'-'A']=1; //M         keys['N'-'A']=2; //N       ...

ISC Program: Predict day of the week from date

Algorithm : 1)Take the last two digits of the year. 2)Divide by 4, discarding any fraction. 3)Add the day of the month. 4)Add the month's key value: JFM AMJ JAS OND 144 025 036 146 5)Subtract 1 for January or February of a leap year. 6)For a Gregorian date, add 0 for 1900's, 6 for 2000's, 4 for 1700's, 2 for 1800's; for other years, add or subtract multiples of 400. 7)For a Julian date, add 1 for 1700's, and 1 for every additional century you go back. 8)Add the last two digits of the year. 9)Divide by 7 and take the remainder. Example : Let's take a date: 26/03/2027 Last two digit of the year = 27 Divide by 4 discard fraction = 27/4 = 6.75 = 6 Add day = 6 + 26 = 32 Month key = 4 + 32 = 36 Add year code = 36 + 6 = 42 Now add two digits of the first year = 42 + 27 = 69 Now get the remainder after dividing by 7 = 69%7=6 So 1 is Sunday so 6 is Friday So 27/03/2027 Program : import java.util.Scanner; public class daydate {     public static void main(String[] arg...