www.webdeveloper.com
Results 1 to 10 of 10

Thread: Selecting only the first 50 characters of a certain column with mysql.

  1. #1
    Join Date
    Jan 2006
    Location
    Israel
    Posts
    178

    Selecting only the first 50 characters of a certain column with mysql.

    I know that there is a special artibute for this, But i can't seem to remember what it is...

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    use the substring function:

    Code:
    SELECT SUBSTRING(column,0,50) FROM your_table;
    http://dev.mysql.com/doc/refman/5.0/...functions.html
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  3. #3
    Join Date
    Jan 2006
    Location
    Israel
    Posts
    178
    Thanks Chazz!!!

  4. #4
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634

    Thumbs up

    by the way, i have to say i am very happy to see that your first idea was to use SQL.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  5. #5
    Join Date
    Dec 2004
    Posts
    439
    is it possible to alias a column and use SUBSTR?

    like this:

    SELECT SUBSTRING(column,0,50) as columnSummary FROM your_table;

  6. #6
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    of course it is.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  7. #7
    Join Date
    Dec 2004
    Posts
    439
    I tried it just like that, and it didn't seem to work, is my syntax wrong, or do i need to review my php?

  8. #8
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    maybe you should post some code.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  9. #9
    Join Date
    Dec 2004
    Posts
    439
    well i have already found a work around for this, and because i am on a tight schedule for work, i'll have to move on for now. I appreciate the help, next time i need to use the SUBSTRING function, I will try your suggestion, and If i continue having problems, I will return here and post the code.

    Thanks again chazzy,
    db.

  10. #10
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    ok, well most likely either the database version/vendor you use doesn't support substring (at least not that function name) or you have another error in your code.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles