Informatics Practices
In a Database Karnataka_Sangam there are two tables with the instances given below :
Table : STUDENTS
| ADMNO | NAME | CLASS | SEC | RN | ADDRESS | PHONE |
|---|---|---|---|---|---|---|
| 1211 | Meena | 12 | D | 4 | A-26 | 3245678 |
| 1212 | Vani | 10 | D | 1 | B-25 | 5456789 |
| 1213 | Meena | 12 | A | 1 | ||
| 1214 | Karish | 10 | B | 3 | AB-234 | 4567890 |
| 1215 | Suraj | 11 | C | 2 | ZW12 | 4345677 |
Table : SPORTS
| ADMNO | GAME | COACHNAME | GRADE |
|---|---|---|---|
| 1215 | Cricket | Mr. Ravi | A |
| 1213 | Vollyball | Ms. Chadha | B |
| 1211 | Vollyball | Mr. Govardhan | A |
| 1212 | Basket Ball | Mr. Tewani | B |
Write SQL queries for the following :
(i) To count how many addresses are not having NULL values in the address column of STUDENTS table.
(ii) To display Name, Class from STUDENTS table and the corresponding Grade from SPORTS table.
(iii) To display Name of the student and their corresponding Coachnames from STUDENTS and SPORTS tables.
SQL Joins & Grouping
1 Like
Answer
(i)
SELECT COUNT(ADDRESS) FROM STUDENTS;
Output
+----------------+
| COUNT(ADDRESS) |
+----------------+
| 4 |
+----------------+
(ii)
SELECT S.NAME, S.CLASS, SP.GRADE
FROM STUDENTS S, SPORTS SP
WHERE S.ADMNO = SP.ADMNO;
Output
+-------+-------+-------+
| NAME | CLASS | GRADE |
+-------+-------+-------+
| MEENA | 12 | A |
| VANI | 10 | B |
| MEENA | 12 | B |
| SURAJ | 11 | A |
+-------+-------+-------+
(iii)
SELECT S.NAME, SP.COACHNAME
FROM STUDENTS S, SPORTS SP
WHERE S.ADMNO = SP.ADMNO;
Output
+-------+--------------+
| NAME | COACHNAME |
+-------+--------------+
| MEENA | MR.GOVARDHAN |
| VANI | MR.TEWANI |
| MEENA | MS.CHADHA |
| SURAJ | MR.RAVI |
+-------+--------------+
Answered By
1 Like
Related Questions
Schemas of tables EMPL, Dept, SalaryGrade are being shown below :
EMPL (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) SALARYGRADE (Lowsal, Highsal, Grade) DEPT (Deptno, DeptName, Location)List the department names and the number of their employees.
Schemas of tables EMPL, Dept, SalaryGrade are being shown below :
EMPL (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) SALARYGRADE (Lowsal, Highsal, Grade) DEPT (Deptno, DeptName, Location)List the employee names and the name of their departments.
In a database BANK, there are two tables with a sample data given below:
Table: EMPLOYEE
ENo EName Salary Zone Age Grade Dept 1 Mona 70000 East 40 A 10 2 Mukhtar 71000 West 45 B 20 3 Nalini 60000 East 26 A 10 4 Sanaj 65000 South 36 A 20 5 Surya 58000 North 30 B 30 Table: DEPARTMENT
Dept DName HOD 10 Computers 1 20 Economics 2 30 English 5 (a) To display ENo, EName, Salary and corresponding DName of all the employees whose age is between 25 and 35 (both values inclusive).
(b) To display DName and corresponding EName from the tables DEPARTMENT and EMPLOYEE (Hint: HOD of DEPARTMENT table should be matched with ENo of EMPLOYEE table for getting the desired result).
(c) To display EName, Salary, Zone and Income Tax (Note: Income tax to be calculated as 30% of salary) of all the employees with appropriate column headings.
How is a left join different from a natural join ? Give example.