Results 1 to 5 of 5

Thread: A SQL Query Question!

  1. #1

    Thread Starter
    Member visual poet's Avatar
    Join Date
    Apr 2002
    Location
    In the driver seat of my Firebird...
    Posts
    52

    Exclamation A SQL Query Question!

    I have this query:

    SELECT LEFT(CallerTelNumber, 2) AS Series
    FROM Call
    ORDER BY CallerTelNumber

    The result is when I run it:

    78
    78
    78
    79
    79
    79
    79
    79
    91
    91
    ...

    But what I want, is to group them by that expression I used in the select statement itself 'LEFT(CallerTelNumber, 2) AS Series' to get the following:

    78
    79
    91
    ...

    so i tried using this query...

    SELECT LEFT(CallerTelNumber, 2) AS Series
    FROM Call
    GROUP BY Series
    ORDER BY CallerTelNumber

    I thought it would work but it didn't, so can someone direct me please as to how I can group a resultset by expression, or if there is a workaround, I'd appreicate the tip...

    Thx a lot

    V.P.

    -----------------




    To steal ideas from one person is plagiarism;
    to steal from many is research.

    Visual Poet :^)

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Would a "SELECT DISTINCT LEFT(etc") do the trick for you?

  3. #3
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    Try...

    SELECT DISTINCT LEFT(CallerTelNumber, 2) AS Series
    FROM Call
    ORDER BY CallerTelNumber

  4. #4

    Thread Starter
    Member visual poet's Avatar
    Join Date
    Apr 2002
    Location
    In the driver seat of my Firebird...
    Posts
    52
    I already treid that and it gave me an error, but after I read the error carefully, I found out why it didn't work....

    it should actually be:

    SELECT DISTINCT LEFT(CallerTelNumber, 2) AS Series
    FROM Call
    ORDER BY Series


    Thank you so much for your help

    -----------------




    To steal ideas from one person is plagiarism;
    to steal from many is research.

    Visual Poet :^)

  5. #5
    Lively Member
    Join Date
    Oct 2001
    Location
    Florida
    Posts
    98
    Friend of mine was looking over the shoulder and this was his suggestion

    SELECT LEFT(CallerTelNumber, 2) AS Series
    FROM Call
    GROUP BY LEFT(CallerTelNumber, 2)
    ORDER BY CallerTelNumber

    EDIT: didn't work so he suggested this.

Posting Permissions

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



Click Here to Expand Forum to Full Width