The Insert Into Select statement

The INSERT INTO SELECT statement copies data from one table and inserts it into another table. This statement requires that the data types in source and target tables matches. The existing records in the target table are unaffected. SYNTAX ISNERT INTO table 2 SELECT * FROM table 1 WHERE condition; One can also copy only... Continue Reading →

EXISTS, ANY, ALL

EXISTS: The EXISTS operator is used to check the existence of record in the subquery. It returns TRUE if the subquery returns one or more records. SYNTAX: SELECT column name(s) FROM table name WHERE EXISTS (SELECT column name FROM table name WHERE condition); ANY & ALL : These operators allow you to perform a comparison... Continue Reading →

GROUP BY & HAVING

GROUP BY The GROUP BY statement groups rows that have the same values into summary rows. This statement is often used with aggregate functions like COUNT(), MAX() , MIN() , SUM() , AVG() to group the result-set by one or more columns. Syntax: SELECT <column name(s)> FROM table name WHERE condition GROUP BY <column name(s)>... Continue Reading →

UNION

The MySQL UNION operator is used to combine the result-set of two or more SELECT statements. To apply the UNION operator one must remember following things: Every SELECT statement within UNION must have the same number of columnsThe columns must also have similar data typesThe columns in every SELECT statement must also be in the same order Syntax: SELECT <column name(s)> FROM table1... Continue Reading →

JOINS

The JOIN clause is used to combine rows from two or more tables, based on a related column between them. JOINS are of five types. INNER JOINLEFT JOINRIGHT JOINCROSS JOINSELF JOIN INNER JOIN The INNER JOIN keyword selects records that have matching values in both tables. INNER JOIN Syntax: SELECT <column name(s)> FROM table1 INNER... Continue Reading →

Column Aliases

The column that you select in a query can be given a different name i.e. column alias name for output purposes. For instance consider a table named school and it has a column class, so the name of the column class can be changed to any other name like Standard and can be displayed as... Continue Reading →

SUM, AVG & COUNT

SUM SUM() is used to calculate the total numeric sum of a column, i.e. all the numeric values will be added and will be displayed as result. SYNTAX select SUM(columnname) from tablename where condition; EXAMPLE select SUM(Score) from students; AVG AVG() returns the average of the numeric values of a specific column. SYNTAX select AVG(columnname)... Continue Reading →

MAX, MIN & LIMIT

MAX() is used to find out the maximum value of a selected column. Where as MN() is used to find the minimum value. The use of both max and min is very simple in MYSQL, even a child can learn to use it! SYNTAX: MAX() : Select MAX(columnname) From tablename Where condition; MIN(): Select MIN(columnname)... Continue Reading →

DELETE , ALTER & DROP Command

DELETE While working with tables, one may reach a situation where he/she no longer needs some rows of data. In such a case one would like to remove such rows. This can be done by using the DELETE command. The DELETE command removes rows from a table. This removes the entire rows, not individual field... Continue Reading →

UPDATE Table

UPDATE Sometimes one needs to change some or all the values in a particular row that is already existing. This can be done using the UPDATE command. It specifies the rows to be changed using the WHERE clause, and the new data using the SET keyword. The new data can be a specified constant, an... Continue Reading →

Handling NULLS

The empty values are represented as NULLS in a table. If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value. A NULL value is different from ZERO. NULL... Continue Reading →

ORDER BY Clause

Whenever a SELECT query is executed, the resulting rows emerge in a pre-decided order. One can sort the results or a query in a specific order using the 'ORDER BY' clause. The ORDER BY clause allows string of query results by one or more columns. The sorting can be done either in ascending order or... Continue Reading →

AND , OR & NOT

AND, OR & NOT are used when the conditions for selecting an entry are more specific. These keywords are used along with WHERE. They are the logical operators. They can also be used with these symbols. AND (&&) OR (||) NOT (!) Syntax: 1. SELECT column name...[column names] from Table name WHERE(condition 1 AND condition... Continue Reading →

The WHERE Clause

Sometimes a table may contain a huge number of rows, so when the user wants to see a particular row or a particular data and selects all the rows , then it will be problematic as it takes longer time to find out that particular information from such a big table, So in order to... Continue Reading →

Select Query

The select query is used to display the contents of the table. It can either be used to display the entire table, specific columns, columns with some particular values or specific cases. The different ways in which select can be used are as follows: 1 . Select * It is used to select all the... Continue Reading →

Inserting values in a table in MySQL

After the creation of table one needs to insert the values. This is done using the 'INSERT INTO' query, it is used in many ways. The examples below show the uses on this query. Example 1 insert into students values(1,'Emily',12,'A','Physics'); insert into students values(2,'Lilly',12,'C','Biology'); In the above query after the 'insert into' command we write... Continue Reading →

Creating Tables in MySQL

After creating the database, the user must know the queries to create table, insert values in the table, selecting the values and displaying them, deleting a row, etc. CREATE TABLE To create table the 'CREATE TABLE' query is used as shown in the example below. create table students(Roll int, Name varchar(10), Class int, Section varchar(5),... Continue Reading →

Databases in MySQL

To start with databases in MySQL we use different queries for creating and using the databases. First of all to start with the basics we must know how to create a database in MySQL. It is done using the 'CREATE DATABASE (name)' query. Simply open the MySQL Command Line Client on your PC/laptop. Enter your... Continue Reading →

Classification of SQL Statements

SQL, technically speaking is a data sublanguage that is it is a language used to interact with database. In other words all SQL statements are instructions to the database only. And that is where it differs from general purpose programming languages like C or CPP. SQL provides many different types of commands used for different... Continue Reading →

Data Definition Language (DDL)

A database scheme is specified by a set of definitions which are expressed by a special language called a data definition language DDL the result of compilation of DDL statements is a set of tables which are stored in a special file called data dictionary or directory. Whenever a data is read or modified in... Continue Reading →

Processing Capabilities of SQL

The SQL has proved to be a language that can be used by both casual users as well as skilled programmers. It offers a variety of processing capabilities, simpler ones of which maybe used by the former and the more complex by the latter class of users. Processing capabilities are as follows: Data definition language... Continue Reading →

Keys

It is important to be able to specify how rows in relation are distinguished conceptually, rows are distinct from one another, but from a database perspective the difference among them must be expressed in terms of their attributes. Keys come here for a rescue! Primary key A primary key is a special relational database table... Continue Reading →

Relational Database Model

In relational database model, the data is organized into tables(i.e. , rows and columns). These table are called relations. A row in a table represents a relationship among a set of values. Since a table is a collection of such relationships, it is generally referred to using the mathematical term, relation, from which the relational... Continue Reading →

DBMS

Introduction A database can be defined as a collection of interrelated data stored together to serve multiple actions. It is basically a computer based record keeping system. The collection of data usually referred to as the database, contains information about one particular enterprise. The data is stored in a such a way that it is... Continue Reading →

MySQL

Introduction to MySQL MySQL is a freely available open source Relational Database Management System (RDBMS) which uses Structured Query Language (SQL). User can store the information in the form of tables in a MySQL databases. One database can have as many tables as the user wants to store, and each table can have as many... Continue Reading →

Binary Search Tree

# include <iostream> # include <cstdlib> using namespace std; struct nod//node declaration { int info; struct nod *l; struct nod *r; }*r; class BST { public://functions declaration void search(nod *, int); void find(int, nod **, nod **); void insert(nod *, nod *); void del(int); void casea(nod *,nod *); void caseb(nod *,nod *); void casec(nod *,nod... Continue Reading →

Binary Heap

#include <iostream> #include <cstdlib> #include <vector> #include <iterator> using namespace std; class BHeap { private: vector <int> heap; int l(int parent); int r(int parent); int par(int child); void heapifyup(int index); void heapifydown(int index); public: BHeap() {} void Insert(int element); void DeleteMin(); int ExtractMin(); void showHeap(); int Size(); }; int main() { BHeap h; while (1)... Continue Reading →

Common Running Times

Linear Time An algorithm that runs in O(n), or linear, time has a very natural property: Its running time is at most a constant factor times the size of the input. One basic way to get an algorithm with this running time is to process the input in a single pass, spending a constant amount... Continue Reading →

Programming Principles

•Problem specification –our approach must be to determine overall goals, but precise ones, and then slowly divide the work into smaller problems until they become of manageable size. •Program design –Each part of a large program must be well organized, clearly written, and thoroughly understood, •Choice of  data structures –How they are arranged in relation... Continue Reading →

Doubly Linked List

Doubly linked list is a type of linked list in which each node apart from storing its data has two links. The first link points to the previous node in the list and the second link points to the next node in the list. The first node of the list has its previous link pointing to... Continue Reading →

Linear Linked List

Representation of Linear linked list Suppose we want to store the list of integer numbers, then the linear linked list can be represented in memory with the following declarations.                         typedef struct nodetype                         {                                     int info;                                     struct nodetype *next;                         }node;                         node *head; The above declaration define a new data type,... Continue Reading →

Machine Learning

Briefing in Python Machine Learning (ML) is that field of computer science with the help of which the computer systems can provide a sense to data in much the same way as human beings do. It is a type of artificial intelligence that extracts patterns out of raw data by using an algorithm or method.... Continue Reading →

List Length in Python

The length of a list can be calculated in Python by using various methods. The built-in len() method in Python is widely used to calculate the length of any sequential data type. It calculates the number of elements or items in a list and returns the same as the length of the list. l=[2,4,6,8,10] print("The length of... Continue Reading →

Sum of elements of array

#include <iostream> using namespace std; int main (){ int arr[] = {6,12,4,7,9 }; int n = 7, sum = 0; for(int i = 0; i<n ; i++){ sum+=arr[i]; } cout<<"The array sum is "<<sum; return 0; }

Transpose of a matrix in C

#include <stdio.h> int main() { int matrix[10][10], transpose[10][10], row, col, i, j; printf("Enter rows and columns: "); scanf("%d %d", &row, &col); printf("\nEnter matrix elements:\n"); for (i = 0; i < row; ++i) for (j = 0; j < col; ++j) { printf("Enter element a%d%d: ", i + 1, j + 1); scanf("%d", &matrix[i][j]); } printf("\nEntered... Continue Reading →

Matrix Addition in C

#include <stdio.h> int main() { int row, col, mat1[100][100], mat2[100][100], matsum[100][100], i, j; printf("Enter the number of rows: "); scanf("%d", &row); printf("Enter the number of columns"); scanf("%d", &col); printf("\nEnter elements of 1st matrix:\n"); for (i = 0; i < row; ++i) for (j = 0; j < col; ++j) { printf("Element a%d%d: ", i +... Continue Reading →

Hosoya’s Triangle or Fibonacci Triangle in C

The Hosoya's triangle (originally Fibonacci triangle) is a triangular arrangement of numbers as it is shown in pascal triangle based on the Fibonacci series. #include<stdio.h> #include<stdlib.h> int main(){ int a=0,b=1,i,c,n,j; system("cls"); printf("Enter the number of lines you want:"); scanf("%d",&n); for(i=1;i<=n;i++) { a=0; b=1; printf("%d\t",b); for(j=1;j<i;j++) { c=a+b; printf("%d\t",c); a=b; b=c; } printf("\n"); } return 0; }

Triangular Number Pattern in C

#include<stdio.h> #include<stdlib.h> int main(){ int i,j,k,l,n; system("cls"); printf("enter the range="); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=n-i;j++) { printf(" "); } for(k=1;k<=i;k++) { printf("%d",k); } for(l=i-1;l>=1;l--) { printf("%d",l); } printf("\n"); } return 0; }

Matrix Multiplication in C

#include <stdio.h> int main() { int m, n, p, q, c, d, k, sum = 0; int first[10][10], second[10][10], multiply[10][10]; printf("Enter number of rows and columns of matrix 1 \n"); scanf("%d%d", &m, &n); printf("Enter elements of first matrix\n"); for (c = 0; c < m; c++) for (d = 0; d < n; d++) scanf("%d",... Continue Reading →

Automorphic number in C

An Automorphic number is a number whose square ends with the same digits as the original. example: 5, 6 etc. #include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int num, square, temp, last; int n =0; printf("Enter a number \n"); scanf("%d",&num); square = num*num; temp = num; while(temp>0){ n++; temp = temp/10; } int den =... Continue Reading →

C program to swap 2 numbers without using 3rd variable

It can be done using two methods: By using + and -By using * and / Method 1: By using + and - #include<stdio.h> int main() { int num1, num2; printf("Enter first number: ") ; scanf("%d",&num1); printf("\nEnter second number: ") ; scanf("%d",&num2); printf("\n Before swapping \n number_1= %d \n number_2 = %d",num1,num2); num1=num1+num2; num2=num1-num2; num1=num1-num2;... Continue Reading →

Easy Python programs

Print the ASCII value of Characters charr =(input("Enter a charcater")) print("The ASCII value of '" + charr + "' is", ord(charr)) Find the roots of quadratic equation import cmath a = int(input("Enter the value of a ")) b = int(input("Enter the value of b ")) c = int(input("Enter the value of c ")) # calculating... Continue Reading →

Area and Circumference of circle in python

#area and circumference of circle rad=float(input("Enter the radius of the circle ")) area= 3.14*rad*rad print("Area of the circle of given radius is = ", area) circum= 2*3.14*rad print("Circumference of the circle of given radius is = ", circum)

To check for Armstrong number in C

Armstrong number is a number which is equal to the sum of cubes of its digits. e.g. 0, 1, 153 etc are the Armstrong numbers. Demonstration: 153=(1*1*1)+(5*5*5)+(3*3*3) cube of 1=1 cube of 5=125 cube of 3=27 1+125+27=153 #include<stdio.h> int main() { int n,q,sum=0,temp; printf("Enter a number="); scanf("%d",&n); temp=n; while(n>0) { q=n%10; sum=sum+(q*q*q); n=n/10; } if(temp==sum) printf("The given... Continue Reading →

Calculate Compound Interest using Python

Formula for compound interest : =final amount=initial principal balance=interest rate=number of times interest applied per time period=number of time periods elapsed def compound_interest(principle, rate, time): CI = principle * (pow((1 + rate / 100), time)) print("Compound interest : ", CI) p=int(input("Enter Principal amount: ")) r=int(input("Enter interest rate: ")) t=int(input("Enter time period: ")) compound_interest(p, r, t)

Calculate simple interest using python

Formula for simple interest is : (principal amount* rate of interest* time period)/100 SI= (P*R*T)/100 p=int(input("Enter the principal amount ")) r=int(input("Enter the interest rate per annum ")) t=int(input("Enter the time period in years ")) simple_interest=(p*r*t)/100 print("SIMPLE INTEREST = ", simple_interest)

Fibonacci Series

Fibonacci series is a series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. e.g. 0, 1, 1, 2, 3, 5, 8, etc. The Rule is to write a Fibonacci series is: xn = xn−1 + xn−2 where: xn is term number "n"xn−1 is the previous term (n−1)xn−2 is the term before that (n−2)... Continue Reading →

Binomial Coefficient

Binomial coefficient is a positive integer that occur as coefficient in the Binomial Theorem. It can be defined as the coefficient of the monomial Xk in the expansion of (1 + X)n . This coefficient also occurs in the formula given below #include <stdio.h> int Coeff(int n, int k) { if (k > n) return 0; if (k... Continue Reading →

Factorial of a Big Number

#include<stdio.h> int main() { int arr[200],n,count,temp,i; arr[0]=1; count=0; printf("Enter the number whose factorial you want to find: "); scanf("%d",&n); for(; n>=2; n--) { temp=0; for(i=0; i<=count; i++) { temp=(arr[i]*n)+temp; arr[i]=temp%10; temp=temp/10; } while(temp>0) { arr[++count]=temp%10; temp=temp/10; } } for(i=count; i>=0; i--) printf("%d",arr[i]); return 0; }

HCF and LCM

HCF can be defined as the Highest Common Factor. It means the greatest which can exaclty divide the given numbers without the remainder. It is also known as Greatest Common Divisor (GCD). Program to find the HCF of 2 numbers. #include <stdio.h> int main() { int num1, num2, i, hcf; printf("Enter two numbers whose HCF... Continue Reading →

Tower of Hanoi

Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 1) Only one disk can be moved at a time.2) Each move consists of taking the upper disk from one of... Continue Reading →

Quick Sort

#include<stdio.h> void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } int partition(int arr[], int p , int q) { int x= arr[p]; int i= p; for(int j=p+1;j<=q;j++) { if(arr[j]<x) { i++; swap(&arr[i],&arr[j]); } } swap(&arr[p],&arr[i]); return i; } void QuickSort(int arr[],int p, int q) { if(p<q) {... Continue Reading →

Merge Sort

#include<stdio.h> void mergesort(int a[],int i,int j); void merge(int a[],int i1,int j1,int i2,int j2); int main() { int a[30],n,i; printf("Enter no of elements:"); scanf("%d",&n); printf("Enter array elements:"); for(i=0;i<n;i++) scanf("%d",&a[i]); mergesort(a,0,n-1); printf("\nSorted array is :"); for(i=0;i<n;i++) printf("%d ",a[i]); return 0; } void mergesort(int a[],int i,int j) { int mid; if(i<j) { mid=(i+j)/2; mergesort(a,i,mid); //left recursion mergesort(a,mid+1,j); //right... Continue Reading →

Generating Random numbers in a given range.

#include <stdio.h> #include <stdlib.h> int main() { int num, randomnum; printf("Enter the number of random numbers you want to enter: \n"); scanf("%d",&num); printf("%d Random no. b/w to 10-99: \n",num); while (num--) { randomnum=rand()%90+10; printf("%d\n",randomnum); } getch(); return 0; }

Insertion sort

This program also calculates the time taken by the insertion sort function to run using time() functions. In this program the user generates random numbers using the rand() function in an array and then applies insertion sort to it. Large input is taken in order to get some value of the time taken by the... Continue Reading →

Linked Lists

Menu Driven Program For All Operations #include <stdio.h> #include <iostream> #include <limits.h> #include <stdlib.h> #include <bits/stdc++.h> using namespace std; struct node { int data; struct node *next; }; struct header { float avg; int max1,min1,max2,min2,totalnode; struct node *next; }; void headerfunc(struct header *); void insertf(struct header *); void deletef(struct header *); void bubble_sort(struct header *);... Continue Reading →

Arrays

Menu Driven Program For All Operations #include <stdio.h> #include <iostream> #include <limits.h> #include <stdlib.h> using namespace std; void insert(int *ar,int*n); void deletef(int *ar,int*n); void bubble_sort(int *ar,int*n); void display(int *ar,int*n); void avg(int *ar,int*n); void max_min(int *ar,int*n); void max2_min2(int *ar,int*n); void disp_odd(int *ar,int*n); void disp_even(int *ar,int*n); int main(void) { int n=0,ar[1000],i=0,c=0; cout<<"Enter size of array(max. 999) :... Continue Reading →

LOOP LEARNING : Loop, Increment, Decrement

Example: While Loop i=1 while i <= 10:   print (i)   i=i+1 OUTPUT Example: Range Function print ("range(10) --> ", list(range(10))) print ("range(0,20) --> ", list(range(0,20))) print ("range(10,20) --> ", list(range(10,20))) print ("range(0,20,2) --> ", list(range(0,20,2))) print ("range(-10,-20,2) --> ", list(range(-10,-20,2))) print ("range(-10,-20,-2) --> ", list(range(-10,-20,-2))) OUTPUT Examples: For Loop for i in range(0,10):   print (i) OUTPUT for i in range(0,20,2):   print (i) OUTPUT for i in range(0,-10,-1):   print (i) OUTPUT Example: Print table of 5 for i in range(1,11):   print (5," * ", i , " = ", i * 5) OUTPUT Example: Sum all numbers from 1 to 10 s=0 for i in range(1,11):   s=s+i print ("Sum is --> ",s) OUTPUT

Book class 2

Imagine a publishing company that markets both books and audio- cassette version of its works. Create a class Publication in C++ that stores the title (a string) and price (type float) of a publication. From this class derive two classes: Book, which adds a page count and Tape, which adds playing time in minutes. These... Continue Reading →

Distance Measure

Define two classes Distance1 and Distance2 in C++. Distance1 stores distance in miles and Distance2 in kmeters & meters. Reads values of the class objects and adds one object of Distance1 with the object of Distance2 class. The display should be in the format of miles or kmeters & meters depending on the type of... Continue Reading →

Volume of box 1

Design a class named Box whose dimensions are integers and private to the class. The dimensions are labelled: length l, breadth b, and height h. The default constructor of the class should initialize l, b, h and to 0. The parameterized constructor Box(int length, int breadth, int height) should initialize Box's l, b and h... Continue Reading →

ComputerUserAccess 1

Users of the computer have profile which consists of Name, Password, and Access Rights. Access rights take on values X, R, W, and A. It is possible to have default values for Password and Access rights which are the first three letters of the Name and ALL respectively. Users can change their password and access... Continue Reading →

Class and Objects 3

Create a class Employees which have a number, rank, and salary. When an employee is first recruited then all these are given values of 0. Upon confirmation, the actual values of these are entered for the employee. At the time of promotion their rank can be incremented by 1 and an employee gets an increment... Continue Reading →

BankAccountClass 2

Define a class in C++ to represent a bank account. Include the following members: Data members: a) Name of the depositor containing charecters and space only b) Account number as of integer type of 4 digit c) Type of account as either saving or current d) Balance amount in the account positive integer Member functions:... Continue Reading →

You have been given a set of complex number. It is desired to add and substract the complex number.

Input Format First line contains one integer representing the real part of first complex number. Second line contains one integer representing the imaginary part of first complex number. Third line contains one integer representing the real part of second complex number. Fourth line contains one integer representing the imaginary part of second complex number. Constraints... Continue Reading →

Python beginner’s programs.

(Without Inputs From User) "Hello World" in python. print ("Hello World") OUTPUT Adding two numbers in python. a = 10 b = 220 c = a + b        print (a, ” + “, b, ” –> “, c) OUTPUT Concatenation of Strings. a = "Bhagat" b =  "Singh" c = a + b    print (a, ” + “, b, ” –> “, c) OUTPUT (With Inputs From User) Adding Two Numbers in python. a = int(input(“Enter First No: “)) b = int(input(“Enter Second No: “)) c = a + b print (a, ” + “, b, ” –> “, c) OUTPUT Concatenation Of Strings. a = input(“Enter First String: “) b = input(“Enter Second String: “) c = a + b    print  (a, ” + “, b, ” –> “, c) OUTPUT

Why Python?

The canonical, “Python is a great first language”, elicited, “Python is great last language!” -Noah Spurrier Python is an easy to learn, powerful programming language. It has an efficient high-level data structure and a simple but efficacious approach to object-oriented programming. It has an elegant syntax and dynamic typing plus an interpreted nature. All these... Continue Reading →

C++ & Object Oriented Programming

“C++: where friends have access to your private members.” — Gavin Russell Baker. C++ is an object oriented computer language created by extraordinary computer scientist Bjorne Stroustrop as part of the evolution of the C family of languages. It is a general purpose programming language and is widely used these days for competitive programming. It has... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started