1

I'm trying to return the records of a table where three columns match up, but i'm getting no results in return. Any suggestions?

SELECT *
FROM Flights
WHERE Departure_IATA_Code = 'STN'
  AND Arrival_IATA_Code = 'DBN'
  AND Departure_Date = 2018-04-16

Create table statements

CREATE TABLE `Flights` (
 `Flight_Number` varchar(50) NOT NULL DEFAULT '',
 `Aircraft_ID` int(7) NOT NULL DEFAULT '0',
 `Departure_IATA_Code` varchar(3) NOT NULL DEFAULT '',
 `Departure_Date` date NOT NULL,
 `Arrival_IATA_Code` varchar(3) NOT NULL DEFAULT '',
 `Cost` int(7) NOT NULL,
 `Departure_Time` time NOT NULL,
 `Flight_Duration` time NOT NULL,
 PRIMARY KEY (`Flight_Number`,`Aircraft_ID`,`Departure_IATA_Code`,`Departure_Date`,`Arrival_IATA_Code`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
  • 1
    Yes, check your query without the filters, one by one. What makes you think this is wrong? Maybe there is no data with these conditions. – Balazs Papp Apr 3 '18 at 21:59
  • 3
    date='2018-4-16' missing single quotes :/ – domin thomas Apr 3 '18 at 22:00
  • 1
    Please Edit your question and add the CREATE TABLE statements for the tables in question adding the desired output. Use formatted text please, no screen shots – Evan Carroll Apr 3 '18 at 22:04
  • It was the missing quote marks for the date. I was trying to do it as a prepared statement in php. – domin thomas Apr 3 '18 at 22:14
  • @dominthomas retract the question if you have the answer and it was a typo that serves no other purpose. – Evan Carroll Apr 4 '18 at 7:10
1

Try it:

SELECT *
FROM Flights
WHERE Departure_IATA_Code = 'STN'
AND Arrival_IATA_Code = 'DBN'
AND Departure_Date = '2018-04-16';
| improve this answer | |
  • Departure_Date is already a date. No need for the conversion. – ypercubeᵀᴹ Apr 4 '18 at 8:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.