![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| 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 | |||
| Advertisements |
| | #2 | ||
| 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? http://dev.mysql.com/doc/refman/5.0/...functions.html <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. | |||
| | #3 | ||
| 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? > > http://dev.mysql.com/doc/refman/5.0/...functions.html > > <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 | |||
| | #4 | ||
| On Mon, 01 May 2006 11:49:23 +0100, José Carlos Santos wrote: > On 01-05-2006 11:28, Kai Ruhnau wrote: >> http://dev.mysql.com/doc/refman/5.0/...functions.html >> >> <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? -- 80. If my weakest troops fail to eliminate a hero, I will send out my best troops instead of wasting time with progressively stronger ones as he gets closer and closer to my fortress. --Peter Anspach's list of things to do as an Evil Overlord | |||
| | #5 | ||
| On 01-05-2006 17:00, Peter H. Coffin wrote: >>> http://dev.mysql.com/doc/refman/5.0/...functions.html >>> >>> <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 | |||
| | #6 | ||
| On Mon, 01 May 2006 18:02:51 +0100, José Carlos Santos wrote: > On 01-05-2006 17:00, Peter H. Coffin wrote: > >>>> http://dev.mysql.com/doc/refman/5.0/...functions.html >>>> >>>> <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. No wasted time; it just looked like exactly what I was expecting to see, and it would have indicated a flaw in my understanding if it didn't work. I would have liked to fix that flaw if I was wrong. -- 94. When arresting prisoners, my guards will not allow them to stop and grab a useless trinket of purely sentimental value. --Peter Anspach's list of things to do as an Evil Overlord | |||
| Featured Websites | ||||
|
![]() |
| Tags: fields, newbie, truncate |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SQL Search Multiple Fields ?? | Nikolai Chuvakhin | PHP | 0 | 07-01-2007 3:18 PM |
| TRUNCATE and OPTIMIZE from Access to MySQL | Mike Easter | Database | 5 | 06-10-2007 12:20 AM |
| Exporting BIT fields in MySQL 5 | Adam Lipscombe | Database | 0 | 05-31-2007 8:48 PM |
| Can you add/remove fields.. | Khai | Database | 4 | 05-31-2007 8:48 PM |
| Indexes on text fields | Rune | Database | 0 | 05-31-2007 8:42 PM |
| Featured Websites | ||||
|