Practice SQL Interview Questions
We’ve finally come to the last part of this question. Question D is presented below again for your convenience.
Part D: Write a SQL statement to insert rows into a table called highAchiever(Name, Age), where a salesperson must have a salary of 100,000 or greater to be included in the table.
Looking at part D, it’s easy to come up with the SQL to specify the condition that the salary of the salesperson must be greater or equal to 100,000. It would look like this "WHERE SALARY >= 100000". The only slightly difficult part of this question is how we insert values into the highachiever table while selecting values from the salesperson table. It turns out that the SQL for this is:
Because we are inserting values into the highAchiever table based off of what we select from another table, we don’t use the "Values" clause that we would normally use when inserting. This is what a regular insertion would look like (note the use of the "values" clause):
As you can see the answer to this one is pretty simple. Click next below to read part 2 of our practice SQL interview questions.