Q. In a Database, there are two tables given below :
Write SQL Queries for the following :
(i) To display employee ids , names of employees, job ids with corresponding job titles.
(ii) To display names of employees, sales and corresponding job titles who have achieved sales more than 1300000.
(iii) To display names and corresponding job titles of those employees who have ‘SINGH’ (anywhere) in their names.
(iv) Identify foreign key in the table EMPLOYEE.
(v) Write SQL command to change the JOBID to 104 of the EMPLOYEE with ID as E4 in the table ‘EMPLOYEE’ .
Consider this table --
You can understand by seeing this video ---
Answer =
(i) SELECT EMPLOYEEID , NAME , EMPLOYEE.JOBID , JOBTITLE FROM EMPLOYEE NATURAL JOIN ON JOB ;
(ii) SELECT NAME , SALES , JOBTITLE FROM EMPLOYEE , JOB WHERE EMPLOYEE.JOBID = JOB.JOBID AND SALES > 1300000 ;
(iii) SELECT NAME , JOBTITLE FROM EMPLOYEE , JOB WHERE EMPLOYEE.JOBID = JOB.JOBID AND NAME LIKE “%SINGH%” ;
(iv) JOBID
(v) UPDATE EMPLOYEE SET JOBID = 104 WHERE EMPLOYEEID = "E4";
In 3rd part I think % are removed surrounding by SINGH is it right ?
ReplyDeleteNo, Question says that 'SINGH' is anywhere.
DeleteFor the first part can we also use equi join?
ReplyDeleteYes, I use natural join because query of natural join are very short.
DeleteI have a doubt in the first questions. It will also print the salary of the JOB table right but they asked us to display only the JOBTITLE of the JOB table so here EQUI JOIN will be better know??
ReplyDeleteIf Name of field name are same in both table then we can use natural join.
Delete
ReplyDeletee
Delete???????
In part 5 of the answer, aren't you supposed to write the SQL query for showing that JOBID is the foreign key.
ReplyDeleteI guess it should be like,
DESC EMPLOYEE;
and hence we will get the output showing JOBID as a foreign key
Question says only to identify.
Deletethank you sir for the solutions
ReplyDeleteWelcome 😊😊😊
Deletelmao what a life saver thanks for this mate
ReplyDeleteWelcome 😊😊😊😊
DeleteThanx..!... Really helped a lot.. ❤❤
ReplyDeleteWelcome 😊😊😊
DeleteJai shree Ram 🚩
DeleteHello, i really get a lot of help from your website, but the thing that came into my mind is that are these answers totally correct. I mean can we viewers can make it sure that it has no error in it.
ReplyDeleteWe always try our best to provide you correct Solution. : )
DeleteI had a doubt. When we specify more than one condition with WHERE clause using OR or AND, we have to enclose the conditions in brackets or not?
ReplyDeleteNo, it is not necessary.
DeleteAlso, when we write ALTER TABLE ADD ----- do we have to put brackets after ADD and write column name datatype in it?
ReplyDeleteNo, but if you want to write without bracket then you have to write 'column' after ADD.
DeleteIs there any condition to use single or double quotes?
ReplyDeleteNo, single quotes and double quotes work in same order.
Deletei dont know why but im gettin - Table not found in statement [SELECT "EMPLOYEEID", "NAME", "E"."JOBID", "JOBTITLE" FROM "EMPLOYEE"]
ReplyDeleteAt first you have to make employee table in your database then run the query.
Deletei have made it yet im getting this error , is it possible if i've done something wrong in the table ??
ReplyDeletePlease send me screen shot on telegram.
DeletePlease do share the output also
ReplyDeleteok, we will try.
Deletein the first part can i use where employee.jobid = job.jobid also?
ReplyDeleteYes.
DeleteThank you unkil i
ReplyDeleteWelcome : )
DeleteUnkil ji mujhko Pani pila dijiye
ReplyDeleteTumko Pani peena h?
DeletePilo lo beta ji 😁
DeleteWhy natural join sir is it really useful
ReplyDeletecan we use natural join for second and third bit also ?
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )