Posts

Student database using MySQL Part 5

Image
EXAMPLE FOR JOINS           Will have an example to combine one or more tables.   SELF JOIN:           SELECT stud1.name AS Student1, stud2.name AS Student2, stud1.district FROM Students stud1, Students stud2 WHERE stud1.rollno <> stud2.rollno AND stud1.district = stud2.district ORDER BY stud1.district;     Create two Alias for the Student table - stud1 and stud2.     This query returns the name of the Student and district if the students are in the same district. Note:  [<> operator is used for not equal condition] INNER JOIN:      SELECT Students.name, Department.hod, Department.name FROM Students INNER JOIN Department ON Students.department=Department.id;      Returns records that have matching values in both tables. CASE: The CASE statement goes through conditions and returns a value when the first condition is met (like an if-then-else statement...

Student database using MySQL Part 3

Image
EXAMPLE FOR MYSQL CLAUSE          Will have an example for MySQL clauses. WHERE  CLAUSE :      SELECT * FROM Students WHERE department=3;     Query filter the records from the Students table based on the department. ORDER BY:      SELECT * FROM Students ORDER BY district DESC;     Sort the result set in descending order. LIMIT:      SELECT * FROM Students LIMIT 2;     This query returns only 2 records from the Students table. GROUP BY:     SELECT COUNT(name), department FROM Students GROUP BY department;     Query group the rows that have the same department.     It returns the count of the students in the same department.      GROUP BY groups the records based on the department and it counts the name of the student based on the grouped department data. HAVING:      SELECT COUNT(name), department FROM Students GR...

Student database using MySQL Part 4

Image
EXAMPLE FOR MYSQL OPERATORS           Will have an example to see how the operators work with the table records.   AND, OR, NOT OPERATORS:      SELECT * FROM Students WHERE department=2 OR district='Madurai';     It returns the Student records if the student department is 2 or the student has a district in Madurai. It returns True if any of the conditions are satisfied.      SELECT * FROM Students WHERE department= 2 AND district='Madurai';        It returns the Student records if the student department is 2 and the student has a district in Madurai. It returns True if both conditions are satisfied.      SELECT * FROM Students WHERE NOT district='Madurai' ORDER BY district DESC;        It returns all the Student records except the student who has a district in Madurai.     The queries filter the records from the Student table based on th...

Student database using MySQL Part 2

Image
EXAMPLE FOR MYSQL TABLE MODIFICATIONS          Will work with an example to modify the table structure.   DESCRIBE TABLE:     The Describe statement is used to describe the structure of the table.      DESCRIBE Students;   UPDATE  QUERY AND SELECT QUERY : An update query is used to update the data in the table. The select query returns all the data in the Students Table.           SELECT * FROM Students;           UPDATE Students SET age= 18 WHERE name = 'Vetri' ALTER TABLE:      Alter statement is used to modify the table structure.      ALTER TABLE Students ADD DateOfBirth date;      ALTER TABLE Students MODIFY COLUMN DateOfBirth year;      ALTER TABLE Students DROP COLUMN DateOfBirth; DELETE TABLE:      DELETE FROM Students WHERE district='Coimbatore';     This...

Introduction to Java

Image
JAVA      James Gosling Invented Java in 1991 and it is developed by Sun Microsystems. But the first version was released in 1995. The current version of Java is Java 17.  Java is an Object Oriented Programming language and it is platform-independent ( Write once and run anywhere ).  Java is easy to compile, and debug and it provides reusability of code that makes development faster.  The following four are important to run, compile and debug the Java application   JDK - Java Development Kit   JRE - Java Runtime Environment  JVM - Java Virtual Machine  Compiler - Java Compiler.    JDK           It is used to provide tools to develop Java applications it comes with Compiler, JRE, and JVM.  COMPILER  Java is the compiler used for compilation.  The compiler will check the program syntax and if it is wrong then throw the error at compile time.   If we don't hav...

MYSQL Tutorial Part 7

Image
  JOINS:     A JOIN clause is used to combine rows from two or more tables, based on a related column between them. INNER JOIN:  Returns records that have matching values in both tables. SELECT column_names FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name; LEFT JOIN:  Returns all records from the left table, and the matched records from the right table. SELECT column_names FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name; RIGHT  JOIN:  Returns all records from the right table and the matched records from the left table. SELECT column_names FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name; CROSS JOIN:  Returns all records from both tables. SELECT column_names FROM table1 CROSS JOIN table2;      Example           SELECT Students.name, Departments.DeptHOD, Departments.name FROM Students INNER      JOIN Departm...

MYSQL Tutorial Part 4

MYSQL CONDITIONS      In this part, will learn about MySQL conditions. Using some operators will filter records from the database table. AND, OR, NOT OPERATORS:      The WHERE clause can be combined with AND, OR, and NOT operators.      The AND and OR operators are used to filter records based on more than one condition: • The AND operator displays a record if  all   the conditions separated by AND are TRUE. • The OR operator displays a record if  any  of the conditions separated by OR is TRUE. • The NOT operator displays a record if the condition(s) is NOT TRUE.      AND Syntax           SELECT * FROM table_name WHERE condition1 AND condition2;      Example:           SELECT * FROM Students WHERE department='ECE' AND district='Thanjavur';      OR Syntax           SELECT * FROM...