Go Back   Free website templates > Web Template Help > PHP and MySQL

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-14-2009, 12:46 AM
bmcoll3278's Avatar
Senior Member
 
Join Date: Jun 2009
Posts: 303
bmcoll3278 is on a distinguished road
Default I need sql help

hey guys here is my query string
mysql_query("SELECT * FROM names WHERE name like '%A%';ORDER BY name ASC");

This Table row contains a single word name My query works but it will pull all names with a (a) in them. Can someone tell me how to match only the first letter of the name so I can display all names with a or b or c you get the idea.

Thanks in advance
__________________
I hope to build a site with something for every body
www.bmcoll.com
Reply With Quote
  #2 (permalink)  
Old 08-14-2009, 01:08 AM
ishkey's Avatar
Mod - Designer
 
Join Date: Aug 2007
Location: ishkey.com
Posts: 3,502
ishkey will become famous soon enough
Default

"ORDER BY Keyword"
The ORDER BY keyword sort the records in ascending order by default.
If you want to sort the records in a descending order, you can use the DESC keyword.

SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
__________________

MySite
Reply With Quote
  #3 (permalink)  
Old 12-14-2009, 04:41 AM
Junior Member
 
Join Date: Dec 2009
Posts: 3
bradstyris is on a distinguished road
Default

I have a little problem given below.

Select student.name, from student, staff where student.name= staff.name

The result of this query gives only common name of both table student and staff table names but i want to common name of student and staff as well as all staff member name. So help me to write such a query.
Reply With Quote
  #4 (permalink)  
Old 12-14-2009, 10:38 PM
bmcoll3278's Avatar
Senior Member
 
Join Date: Jun 2009
Posts: 303
bmcoll3278 is on a distinguished road
Default

easy to do But i need your table structure to do it.
If you want to send me a copy of the sql file so I can see how the table is built I will help.
Reply With Quote
  #5 (permalink)  
Old 12-19-2009, 10:02 AM
enigma1's Avatar
Programmer
 
Join Date: Dec 2009
Location: London, UK
Posts: 127
enigma1 will become famous soon enough
Default

Or if you want to extract just the records where names begin with a you remove the % character from the beginning of the query. Something like:
Code:
mysql_query("SELECT * FROM names WHERE name like 'A%' ORDER BY name");
PS: whats the semicolon doing before the order by with the original query. That should give an sql error.
Reply With Quote
  #6 (permalink)  
Old 01-18-2010, 08:29 AM
Junior Member
 
Join Date: Oct 2009
Posts: 11
warden26 is on a distinguished road
Default

No semicolon.
Reply With Quote
Reply

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:08 AM.