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 > Select from where first charcter starts with J

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-19-05, 23:07
jasong jasong is offline
Registered User
 
Join Date: Jul 2004
Posts: 23
Select from where first charcter starts with J

Hi all,

What would the query be where I select from a table where the first letter of the data in a field starts with a certain letter? For instance J.
Or would I just have to select all and then filter through in php?

Thanks,
Jason
__________________
SnapSlides.Com - Create slideshows online to share with friends and family.
Reply With Quote
  #2 (permalink)  
Old 02-19-05, 23:57
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
select foo from bar where left(qux,1) = 'j'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-19-05, 23:58
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
never a need to filter with php. the only time you would probably need to use php would be for displaying your data in other ways than you can pull it out of the database.


Code:
Select foo from yourtable
where left(foo,1)='j'
Reply With Quote
  #4 (permalink)  
Old 02-20-05, 00:02
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
You won by a minute here, happy? <lol>
Reply With Quote
  #5 (permalink)  
Old 02-20-05, 01:16
jasong jasong is offline
Registered User
 
Join Date: Jul 2004
Posts: 23
Thanks for the replys

So in your examples, in the (), the first word (foo and qux), what do those reference? The field?
Also, is this case-sensitive?

Thanks,
Jason
__________________
SnapSlides.Com - Create slideshows online to share with friends and family.
Reply With Quote
  #6 (permalink)  
Old 02-20-05, 07:36
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
foo is the canonical example of a metasyntactic variable

no, the sql is not case-sensitive
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 02-20-05, 07:42
canman canman is offline
Registered User
 
Join Date: Feb 2005
Posts: 5
Isn't it easier just to say... SELECT foo FROM bar WHERE variable = 'J%'? Or am I missing something obvious here?

Last edited by canman; 02-20-05 at 07:44.
Reply With Quote
  #8 (permalink)  
Old 02-20-05, 08:11
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
well, canman, you could, except that you would want to change it from

... WHERE variable = 'J%'

to

... WHERE variable LIKE 'J%'

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 02-20-05, 12:17
jasong jasong is offline
Registered User
 
Join Date: Jul 2004
Posts: 23
Quote:
WHERE variable LIKE 'J%'
Aye, I shall use that one, I never thought of that.

Thanks all
Jason
__________________
SnapSlides.Com - Create slideshows online to share with friends and family.
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