Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2009
    Posts
    20

    Question Unanswered: Retrieving 1 row from a table

    If I have these columns:
    Itinerary Flight_No
    1 15
    1 329
    2 15
    2 329
    3 101
    3 104
    3 105
    4 606
    5 606
    5 691

    How can I retrieve only the row with itinerary #4 with a general query?
    I've tried DISTINCT but that took away only the repetitive rows.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,934
    Provided Answers: 12
    What's wrong with
    Code:
    SELECT *
    FROM the_table
    WHERE itinerary = 4

  3. #3
    Join Date
    Apr 2009
    Posts
    20
    I need the query to be general so whenever there are any single itineraries, they will show up.
    I tried using COUNT but I need to expand on the query, I think..

    select tic_itinerary_no, count(*)
    from ticket
    group by tic_itinerary_no;

    Thanks.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,934
    Provided Answers: 12
    Code:
    select tic_itinerary_no, count(*)
    from ticket
    group by tic_itinerary_no
    having count(*) = 1

  5. #5
    Join Date
    Apr 2009
    Posts
    20
    works fine now. thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •