If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Simple Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-04-04, 13:53
Strikerz95 Strikerz95 is offline
Registered User
 
Join Date: May 2004
Posts: 28
Simple Question

This is a simple question and I have looked around for the answer but have not been able to find it. How do I return the first character of a string in MySQL. For example the following code returns the firstname of students in a database:

SELECT (first_name) FROM chc_students;

How do I modify that query to return only the first letter of the firstname?
Reply With Quote
  #2 (permalink)  
Old 06-04-04, 14:06
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
I'd use the Left() function.

-PatP
Reply With Quote
  #3 (permalink)  
Old 06-04-04, 15:22
kmfan kmfan is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
Use:
select left("string",1);

returns:
s
Reply With Quote
  #4 (permalink)  
Old 06-04-04, 16:23
Strikerz95 Strikerz95 is offline
Registered User
 
Join Date: May 2004
Posts: 28
Thanks, that worked
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On