Professional Web Applications Themes

How to truncate fields (newbie) - MySQL

Hi all: Suppose that I have a table with fields which can be rather long string of characters. For instance, it can be a table called library concerning the books from a library and the fields might be the title and the author of the books. If I type SELECT title, author FROM library; this might be hard to read on screen. Is it possible to display, say, only the first 20 characters of each field? Best regards, Jose Carlos Santos...

  1. #1

    Default How to truncate fields (newbie)

    Hi all:

    Suppose that I have a table with fields which can be rather long string
    of characters. For instance, it can be a table called library concerning
    the books from a library and the fields might be the title and the
    author of the books. If I type

    SELECT title, author FROM library;

    this might be hard to read on screen. Is it possible to display, say,
    only the first 20 characters of each field?

    Best regards,

    Jose Carlos Santos
    Josť Carlos Santos Guest

  2. #2

    Default Re: How to truncate fields (newbie)

    Josť Carlos Santos wrote:
    > Suppose that I have a table with fields which can be rather long string
    > of characters. For instance, it can be a table called library concerning
    > the books from a library and the fields might be the title and the
    > author of the books. If I type
    >
    > SELECT title, author FROM library;
    >
    > this might be hard to read on screen. Is it possible to display, say,
    > only the first 20 characters of each field?
    [url]http://dev.mysql.com/doc/refman/5.0/en/string-functions.html[/url]

    <snip>

    LEFT(str,len)

    Returns the leftmost len characters from the string str.

    mysql> SELECT LEFT('foobarbar', 5);
    -> 'fooba'

    </snip>

    Greetings
    Kai

    --
    This signature is left as an exercise for the reader.
    Kai Ruhnau Guest

  3. #3

    Default Re: How to truncate fields (newbie)

    On 01-05-2006 11:28, Kai Ruhnau wrote:
    >> Suppose that I have a table with fields which can be rather long string
    >> of characters. For instance, it can be a table called library concerning
    >> the books from a library and the fields might be the title and the
    >> author of the books. If I type
    >>
    >> SELECT title, author FROM library;
    >>
    >> this might be hard to read on screen. Is it possible to display, say,
    >> only the first 20 characters of each field?
    >
    > [url]http://dev.mysql.com/doc/refman/5.0/en/string-functions.html[/url]
    >
    > <snip>
    >
    > LEFT(str,len)
    >
    > Returns the leftmost len characters from the string str.
    >
    > mysql> SELECT LEFT('foobarbar', 5);
    > -> 'fooba'
    >
    > </snip>
    Thanks for your reply, but I don't see how to use it in order to obtain
    the effect that I mentioned: to get only the first 20 characters of each
    field. For instance, it would be grat if

    SELECT LEFT(title,20), LEFT(author,20) FROM library;

    would do just that.

    Best regards,

    Jose Carlos Santos
    Josť Carlos Santos Guest

  4. #4

    Default Re: How to truncate fields (newbie)

    On 01-05-2006 17:00, Peter H. Coffin wrote:
    >>> [url]http://dev.mysql.com/doc/refman/5.0/en/string-functions.html[/url]
    >>>
    >>> <snip>
    >>>
    >>> LEFT(str,len)
    >>>
    >>> Returns the leftmost len characters from the string str.
    >>>
    >>> mysql> SELECT LEFT('foobarbar', 5);
    >>> -> 'fooba'
    >>>
    >>> </snip>
    >> Thanks for your reply, but I don't see how to use it in order to obtain
    >> the effect that I mentioned: to get only the first 20 characters of each
    >> field. For instance, it would be grat if
    >>
    >> SELECT LEFT(title,20), LEFT(author,20) FROM library;
    >>
    >> would do just that.
    >
    > Did you try that? What error did you get? Or did you get the results you
    > were hoping for?
    I thought I had tried and got an error... but now I tried again and it
    worked just fine. Thanks for your help and sorry for wasting your time.

    Best regards,

    Jose Carlos Santos
    Josť Carlos Santos Guest

Similar Threads

  1. PHP Truncate Text
    By Energize in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 2
    Last Post: August 11th, 02:07 AM
  2. newbie: WHERE ... many fields
    By Helmuth Mikkelsen in forum PHP Development
    Replies: 5
    Last Post: November 27th, 10:28 PM
  3. newbie question: combining fields
    By John in forum PHP Development
    Replies: 1
    Last Post: August 31st, 10:59 PM
  4. syslog truncate
    By Sinisa in forum SCO
    Replies: 3
    Last Post: August 1st, 01:24 PM
  5. Truncate Access
    By Ramandeep Singh in forum Microsoft SQL / MS SQL Server
    Replies: 3
    Last Post: July 1st, 07:21 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139