Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help with this question

Author  Topic 

levinll
Starting Member

1 Post

Posted - 2013-10-16 : 10:35:54
Am applying for a job and they have sent me test to complete. One of them requires SQL statement. I tried installing mySQL for my windows machine, but the service keeps shutting down so I can't create/test any code. Therefore I'm looking for any/all help in answering this question.

here's the question:
8. Given the below SQL Server table definitions, write a SQL statement that will retrieve a list of all unique resultId values for a patient with an accountNumber of “M000001234”.

CREATE TABLE [dbo].[Patients](
[id] [int] IDENTITY(1,1) NOT NULL,
[lastName] [varchar](50) NOT NULL,
[firstName] [varchar](50) NOT NULL,
[accountNumber] [varchar](50) NOT NULL,
CONSTRAINT [PK_Patients] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[PatientResults](
[patientId] [int] NOT NULL,
[resultId] [varchar](25) NOT NULL,
[resultDateTime] [datetime] NOT NULL,
[result] [varchar](100) NOT NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[PatientResults] WITH CHECK ADD CONSTRAINT [FK_PatientResults_Patients] FOREIGN KEY([patientId])
REFERENCES [dbo].[Patients] ([id])
GO
ALTER TABLE [dbo].[PatientResults] CHECK CONSTRAINT [FK_PatientResults_Patients]
GO


Thanks to all who help me answer/solve my problem so I can't get this job.

Hommer
Aged Yak Warrior

808 Posts

Posted - 2013-10-16 : 10:46:27
Sorry, but I have to say, if you don't know how to answer this kind of question on a notepad, I don't think you should apply that job.
This is like sql 101. It is for your own good. Even you get the job, it wouldn't last.

quote:
Originally posted by levinll

Am applying for a job and they have sent me test to complete. One of them requires SQL statement. I tried installing mySQL for my windows machine, but the service keeps shutting down so I can't create/test any code. Therefore I'm looking for any/all help in answering this question.

here's the question:
8. Given the below SQL Server table definitions, write a SQL statement that will retrieve a list of all unique resultId values for a patient with an accountNumber of “M000001234”.

CREATE TABLE [dbo].[Patients](
[id] [int] IDENTITY(1,1) NOT NULL,
[lastName] [varchar](50) NOT NULL,
[firstName] [varchar](50) NOT NULL,
[accountNumber] [varchar](50) NOT NULL,
CONSTRAINT [PK_Patients] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[PatientResults](
[patientId] [int] NOT NULL,
[resultId] [varchar](25) NOT NULL,
[resultDateTime] [datetime] NOT NULL,
[result] [varchar](100) NOT NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[PatientResults] WITH CHECK ADD CONSTRAINT [FK_PatientResults_Patients] FOREIGN KEY([patientId])
REFERENCES [dbo].[Patients] ([id])
GO
ALTER TABLE [dbo].[PatientResults] CHECK CONSTRAINT [FK_PatientResults_Patients]
GO


Thanks to all who help me answer/solve my problem so I can't get this job.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-16 : 12:42:21
You say
I tried installing mySQL for my windows machine
and question says
Given the below SQL Server table definitions

Do you atleast realize that MySQL and MS SQL Server are two different RDBMS systems?

As specified in last thread I dont think helping you in getting this test will do you any good.
My suggestion for you would be to start learning basics of SQL and apply once you've enough grip on the subject.

Start with below links

http://www.w3schools.com/sql/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-10-16 : 12:46:33
quote:
Originally posted by levinll


Thanks to all who help me answer/solve my problem so I can't get this job.

Welcome!
Go to Top of Page

maggie21620
Starting Member

27 Posts

Posted - 2013-10-16 : 16:34:59
you could set it up like this:
select distinct
,lastName
,firstName
,accountNumber

from patient table(depends on what that is called)
where patient_account_number = 'M000001234'

seems to me this test is more than just writing a qry i would question if you really wanted to take the position and be straigh up front with them. this is my take on the answer to the question,


none
Go to Top of Page
   

- Advertisement -