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";

40 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. In 3rd part I think % are removed surrounding by SINGH is it right ?

    ReplyDelete
    Replies
    1. No, Question says that 'SINGH' is anywhere.

      Delete
  2. For the first part can we also use equi join?

    ReplyDelete
    Replies
    1. Yes, I use natural join because query of natural join are very short.

      Delete
  3. I 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??

    ReplyDelete
    Replies
    1. If Name of field name are same in both table then we can use natural join.

      Delete
  4. In part 5 of the answer, aren't you supposed to write the SQL query for showing that JOBID is the foreign key.
    I guess it should be like,
    DESC EMPLOYEE;

    and hence we will get the output showing JOBID as a foreign key

    ReplyDelete
  5. thank you sir for the solutions

    ReplyDelete
  6. lmao what a life saver thanks for this mate

    ReplyDelete
  7. Thanx..!... Really helped a lot.. ❤❤

    ReplyDelete
  8. Hello, 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.

    ReplyDelete
    Replies
    1. We always try our best to provide you correct Solution. : )

      Delete
  9. I 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?

    ReplyDelete
  10. Also, when we write ALTER TABLE ADD ----- do we have to put brackets after ADD and write column name datatype in it?

    ReplyDelete
    Replies
    1. No, but if you want to write without bracket then you have to write 'column' after ADD.

      Delete
  11. Is there any condition to use single or double quotes?

    ReplyDelete
    Replies
    1. No, single quotes and double quotes work in same order.

      Delete
  12. i dont know why but im gettin - Table not found in statement [SELECT "EMPLOYEEID", "NAME", "E"."JOBID", "JOBTITLE" FROM "EMPLOYEE"]

    ReplyDelete
    Replies
    1. At first you have to make employee table in your database then run the query.

      Delete
  13. i have made it yet im getting this error , is it possible if i've done something wrong in the table ??

    ReplyDelete
  14. Please do share the output also

    ReplyDelete
  15. in the first part can i use where employee.jobid = job.jobid also?

    ReplyDelete
  16. Thank you unkil i

    ReplyDelete
  17. Unkil ji mujhko Pani pila dijiye

    ReplyDelete
  18. Why natural join sir is it really useful

    ReplyDelete
  19. can we use natural join for second and third bit also ?

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post