Log in  ::  Register  ::  Not logged in

## Interview Questions

 Author Message Julian Fletcher Ten Centuries Group: General Forum Members Points: 1429 Visits: 1118 I work for a company of about 50 people in {REDACTED} and am involved in the recruitment process - we're looking for developers with at least a couple of years' experience in SQL and C#. Part of the process involves asking the candidate a couple of SQL questions, questions which we think aren't too tricky and which shouldn't prove to be too difficult for the sort of people we're looking for. And yet ... we're constantly surprised (and disappointed) how badly most people do. Although the occasional interviewee does answer without any trouble (and usually ends up with a job offer!), we were wondering if the questions are Just Too Difficult.Here they are. What do you think? Any opinions gratefully received.Question #1Consider the tables given and the following code: Table_A ID CustomValue1 11 22 1Table_B ID CustomValue1 212 20 `SELECT *FROM Table_A A JOIN Table_B B ON (A.ID = B.ID)WHERE B.CustomValue = 21SELECT *FROM Table_A A JOIN Table_B B ON (A.ID = B.ID AND B.CustomValue = 21)SELECT *FROM Table_A A LEFT OUTER JOIN Table_B B ON (A.ID = B.ID)WHERE B.CustomValue = 21SELECT *FROM Table_A A LEFT OUTER JOIN Table_B B ON (A.ID = B.ID AND B.CustomValue = 21)`Write down exactly what each of the four select statements would return.Question #2Compare the two pieces of the code:`SELECT SurnameFROM T_EmployeeWHERE DATEDIFF(yy, DateOfBirth, GETDATE()) > 60SELECT SurnameFROM T_EmployeeWHERE DateOfBirth < DATEADD(yy, -60, GETDATE())`What is each trying to achieve? Which one might be the better considering performance? Why?Question #3Please take a look on the following code:`CREATE TABLE T_Employee( EmployeeID int NOT NULL Identity(1, 1), Surname varchar(100) NOT NULL, FirstName varchar(100) NOT NULL, DateOfBirth datetime NOT NULL, CreatedDate datetime NOT NULL, UpdatedDate datetime NULL)GOCREATE TRIGGER T_EmployeeUpdate ON T_Employee FOR UPDATE ASBEGIN DECLARE @EmployeeID int SELECT @EmployeeID = EmployeeID FROM Inserted UPDATE T_Employee SET UpdatedDate = GETDATE() WHERE EmployeeID = @EmployeeIDENDGO`What is the trigger trying to achieve? Will it always succeed? If not, how could it be fixed? Luis Cazares SSC Guru Group: General Forum Members Points: 95243 Visits: 21192 They don't seem extremely difficult. Unfortunately, many people will get them wrong.It seems like a nice test which will separate good from bad ones. However, on question 2, the queries aren't exactly the same and results could vary from one and another. ;-) Luis C.General Disclaimer:Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?How to post data/code on a forum to get the best help: Option 1 / Option 2 Koen Verbeeck SSC Guru Group: General Forum Members Points: 145248 Visits: 13349 They are not too difficult in my opinion. Anyone with at least a year of SQL experience should be able to answer these more or less correct.(and I'm just a measly BI developer :-D)#3 might be a tad more difficult if you have never worked with triggers before. But then again, I almost never work with them and I immediately saw it cannot handle updates on multiple rows at the same time. ;-) How to post forum questions.Need an answer? No, you need a question.What’s the deal with Excel & SSIS?My blog at SQLKover.MCSE Business Intelligence - Microsoft Data Platform MVP dotnetkim SSC Rookie Group: General Forum Members Points: 36 Visits: 10 What are the answers? Koen Verbeeck SSC Guru Group: General Forum Members Points: 145248 Visits: 13349 kimberly_lehman (6/6/2014)What are the answers?Try to answer yourself. Post your answers here and we'll correct them if necessary ;-) How to post forum questions.Need an answer? No, you need a question.What’s the deal with Excel & SSIS?My blog at SQLKover.MCSE Business Intelligence - Microsoft Data Platform MVP dotnetkim SSC Rookie Group: General Forum Members Points: 36 Visits: 10 Ok, well in question 1, it looks to me like all 4 would return the same result, but I didn't test it! Putting a predicate on the ON clause should be the same as putting it in the where clause with an inner join. And the outer join shouldn't change anything because there aren't any non-matching rows. 1 1 1 211 2 1 21 Koen Verbeeck SSC Guru Group: General Forum Members Points: 145248 Visits: 13349 kimberly_lehman (6/6/2014)Ok, well in question 1, it looks to me like all 4 would return the same result, but I didn't test it! Putting a predicate on the ON clause should be the same as putting it in the where clause with an inner join. And the outer join shouldn't change anything because there aren't any non-matching rows. 1 1 1 211 2 1 21The last query is different.You only take one row of table B (since customValue = 21), but you match it against every row of table A.The third row doesn't match (A.ID <> B.ID), so the columns from B are NULL3rd row: 2 1 NULL NULL. How to post forum questions.Need an answer? No, you need a question.What’s the deal with Excel & SSIS?My blog at SQLKover.MCSE Business Intelligence - Microsoft Data Platform MVP dotnetkim SSC Rookie Group: General Forum Members Points: 36 Visits: 10 Aha! I knew there had to be something I was missing. So now to answer the OPs question, did most interviewees give you the same response I gave? Or were most of them way off? dotnetkim SSC Rookie Group: General Forum Members Points: 36 Visits: 10 Number 2 is selecting names of employees over 60. Or specifically, people who were 60 years old by the end of last year, since this is only comparing by year. I have no idea which ones provides better performance. In my experience I either haven't worked with large enough data sets that I needed to spend time optimizing queries, or the companies I worked for were large enough that DBAs would handle the optimizing of queries that took too long to run. Koen Verbeeck SSC Guru Group: General Forum Members Points: 145248 Visits: 13349 kimberly_lehman (6/6/2014)Number 2 is selecting names of employees over 60. Or specifically, people who were 60 years old by the end of last year, since this is only comparing by year. I have no idea which ones provides better performance. In my experience I either haven't worked with large enough data sets that I needed to spend time optimizing queries, or the companies I worked for were large enough that DBAs would handle the optimizing of queries that took too long to run.The second one is better for performance. In the first one, an index on DateOfBirth cannot be used, as the column is inside a calculation.The second one doesn't have this problem.Regarding the remark of Luis saying the results can be different:I think this is becausue DATEDIFF(year,date1,date2) isn't exactly accurate. 20131231 and 20140101 gives a 1 year difference, but in reality they are just 1 day apart. How to post forum questions.Need an answer? No, you need a question.What’s the deal with Excel & SSIS?My blog at SQLKover.MCSE Business Intelligence - Microsoft Data Platform MVP

## Permissions

 You can't post new topics. You can't post topic replies. You can't post new polls. You can't post replies to polls. You can't edit your own topics. You can't delete your own topics. You can't edit other topics. You can't delete other topics. You can't edit your own posts. You can't edit other posts. You can't delete your own posts. You can't delete other posts. You can't post events. You can't edit your own events. You can't edit other events. You can't delete your own events. You can't delete other events. You can't send private messages. You can't send emails. You can read topics. You can't vote in polls. You can't upload attachments. You can download attachments. You can't post HTML code. You can't edit HTML code. You can't post IFCode. You can't post JavaScript. You can post emoticons. You can't post or upload images.

##### Select a forum
 SQL Server 2017      SQL Server 2017 - Administration      SQL Server 2017 - Development SQL Server 2016      SQL Server 2016 - Administration      SQL Server 2016 - Development and T-SQL SQL Server 2014      Administration - SQL Server 2014      Development - SQL Server 2014 SQL Server 2012      SQL 2012 - General      SQL Server 2012 - T-SQL SQL Server vNext      SQL Server 15 - Administration      SQL Server 15 - Development SQL Server 2008      SQL Server 2008 - General      T-SQL (SS2K8)      June 2007 CTP      Working with Oracle      July CTP      SQL Server Newbies      Security (SS2K8)      SQL Server 2008 High Availability      SQL Server 2008 Administration      Data Corruption (SS2K8 / SS2K8 R2)      SQL Server 2008 Performance Tuning Cloud Computing      SQL Azure - Development      SQL Azure - Administration      Amazon AWS and other cloud vendors      General Cloud Computing Questions      CosmosDB      Azure Data Lake      Azure Machine Learning Reporting Services      Reporting Services      Reporting Services 2005 Administration      Reporting Services 2005 Development      Reporting Services 2008/R2 Administration      Reporting Services 2008 Development      SSRS 2012      SSRS 2014      SSRS 2016 Programming      Connecting      General      SMO/RMO/DMO      XML      Service Broker      Powershell      Testing      TFS/Data Dude/DBPro      SSDT      Continuous Integration, Deployment, and Delivery      R Services and R Language Data Warehousing      Integration Services      Strategies and Ideas      Analysis Services      Data Transformation Services (DTS)      Performance Point      Data Mining      PowerPivot      R language      Machine Learning Database Design      Disaster Recovery      Design Ideas and Questions      Relational Theory      Hardware      Virtualization      Security and Auditing SQLServerCentral.com      Anything that is NOT about SQL!      Contests!      Editorials      SQLServerCentral.com Announcements      SQLServerCentral.com Website Issues      Suggestions      Tag Issues with Content      Podcast Feedback      SQLServerCentral.com Test Forum      Articles Requested SQL Server 2005      Administering      Backups      Business Intelligence      CLR Integration and Programming.      Data Corruption      Development      Working with Oracle      SQL Server 2005 Compact Edition      SQL Server 2005 General Discussion      SQL Server 2005 Security      SQL Server 2005 Strategies      SS2K5 Replication      SQL Server Express      SQL Server 2005 Performance Tuning      SQL Server 2005 Integration Services      T-SQL (SS2K5)      SQL Server Newbies SQL Server 7,2000      Administration      Backups      Data Corruption      General      Globalization      In The Enterprise      Working with Oracle      Security      Strategies      SQL Server Newbies      Service Packs      SQL Server CE      Performance Tuning      Replication      Sarbanes-Oxley      T-SQL      SQL Server Agent SQL Server and other platforms      MySQL      Oracle      PostgreSQL      DB2      SQL Server and Sharepoint Older Versions of SQL (v6.5, v6.0, v4.2)      Older Versions of SQL (v6.5, v6.0, v4.2) Career      Certification      Employers and Employees      Events      Job Postings      Resumes and Job Hunters      Presentations and Speaking      Retired Members Testing Center      SQL Server Security Skills      Question of the Day (QOD) Microsoft Access      Microsoft Access Products and Books      Third Party Products         SQLCentric         Extreme Technologies.         Innovartis         Embarcadero         SQL Sentry         Sonasoft         Golden Gate Software         Idera         Lumigent         Red Gate Software         ApexSQL         Quest Software         CA      Discussions about Books         Discuss Programming Books          Discuss XML Books          Discuss T-SQL Books          Discuss Data Warehousing Books          Discuss DTS Books          Discuss SQL Server 2000 Books         Discuss SQL Server 7.0 Books Notification Services      Administration Article Discussions Future Versions      SQL 12

## Search

 Copyright © 2002-2018 Redgate. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.