I’m currently trying to create a query so that I can display which patients had an operation on a specific date, however I keep getting this problem
[Err] 1054 – Unknown column ‘Patient.PatientSurname’ in ‘field list’
The query I am trying to implement is this
SELECT Patient.PatientSurname,
Patient.PatientSex,
Patent.PatientAge,
Doctor.DoctorSurname,
Doctor.DoctorSpecialism
FROM Operation
WHERE (Operation.Date = ‘21/12/2010’);
Is this possibly to do with indexing?
Here is my code for my Patient table
CREATE TABLE Patient
(PatientCode VARCHAR (5) NOT NULL,
PatientSurname VARCHAR (15) NOT NULL,
PatientFirstName VARCHAR (15) NOT NULL,
PatientSex VARCHAR (6) NOT NULL,
PatientAge VARCHAR (3) NOT NULL,
PatientOccupation VARCHAR (15) NOT NULL,
PatientHeight VARCHAR (5) NOT NULL,
PatientWeight VARCHAR (6) NOT NULL,
PatientAddress VARCHAR (20) NOT NULL,
PRIMARY KEY (PatientCode),
);
CREATE TABLE Operation
(OperationCode VARCHAR (6) NOT NULL,
PatientCode VARCHAR (5) NOT NULL,
DoctorCode VARCHAR (6) NOT NULL,
Date DATETIME NOT NULL,
Result VARCHAR (10) NOT NULL,
OperationType VARCHAR (15) NOT NULL,
PRIMARY KEY (OperationCode),
FOREIGN KEY (PatientCode) REFERENCES Patient(PatientCode) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (DoctorCode) REFERENCES Doctor(DoctorCode) ON UPDATE CASCADE ON DELETE RESTRICT );
The problem with your query is you are referencing tables
patientsanddoctorthat are not joined to theoperationtable. You need to join to these other tables to get the data that you want. Based on the details that you have posted, you just need to join your tables:If you need help learning join syntax, then here is a great visual explanation of joins