0

I am just starting to learn SQL.

How do you add a condition to a statement? I am trying to sort the destination to 'BNA' which is the airport code.

 SELECT 
 CHARTER.CUS_CODE,
 CHARTER.DESTINATION "AIRPORT",
 CHARTER.CHAR_DATE, 
 CHARTER.CHAR_DISTANCE,
 CHARTER.AC_NUMBER,
 FROM C.CHARTER ;

 WHERE DESTINATION = 'BNA' ;

Any hints in the right direction would be great.

9
  • 1
    Huh? Not clear on your question. If you want sorted output, add an ORDER BY clause. Commented Feb 21, 2014 at 3:31
  • Well if I just leave the code as "destination", the output would be all the destinations. I just want to sort by one destination and leave out the rest. Commented Feb 21, 2014 at 3:34
  • 1
    When you sort something, your order it. When you leave something out, you filter it. Commented Feb 21, 2014 at 3:39
  • 1
    @Chris did you try the sql in my post? The table in the from clause should most likely be "CHARTER" not "C.HARTER" and you need to put the semicolon at the end of the query only. You have a semicolon after the from clause, which is not needed. The semicolon signals the end of a query. Commented Feb 21, 2014 at 3:44
  • 1
    There is an extra comma after charter.ac_number (sorry I must have glazed over it before) Commented Feb 21, 2014 at 4:22

3 Answers 3

1

The following is your query with the syntax corrected:

SELECT CHARTER.CUS_CODE,
       CHARTER.DESTINATION "AIRPORT",
       CHARTER.CHAR_DATE,
       CHARTER.CHAR_DISTANCE,
       CHARTER.AC_NUMBER
  FROM CHARTER
 WHERE DESTINATION = 'BNA';
  1. The semicolon goes at the end only.
  2. Get rid of "c." from the table name in your from clause. You might have been thinking of giving it an alias of "c" which, if if that's the case, you would put it after the table name (and then use it as a prefix for each field).
Sign up to request clarification or add additional context in comments.

Comments

1
 SELECT 
 CHARTER.CUS_CODE,
 CHARTER.DESTINATION "AIRPORT",
 CHARTER.CHAR_DATE, 
 CHARTER.CHAR_DISTANCE,
 CHARTER.AC_NUMBER,
 FROM C.CHARTER 
 WHERE DESTINATION = 'BNA' ;

The ; character is a statement terminator; you only need one per SQL statement.

Comments

1

there is ";" at the end of the FROM statement, remove it. and try the sql again. Pay attention with the double quote too on the AIRPORT text.

SELECT CHARTER.DESTINATION + 'AIRPORT ' 
 FROM C.CHARTER
 WHERE DESTINATION = 'BNA' ;

2 Comments

I think he is just giving that column an alias of "airport", in which case it's fine. He probably doesn't want to concatenate the word "airport" to every destination.
I see, thanks for the info. I always use "AS" to create Alias.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.