المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to MySQL Select Statement - Searching Data



bahattab
24-08-2009, 01:40 AM
SQL Select Statement - Searching Data





http://www.atyafonline.com/vb/imgcache/3498.png (http://z.about.com/d/php/1/0/9/-/-/-/MySQL5.gif)


Although in our test database we only have two entries and everything is easy to find, as a database grows it is useful to be able to quickly search the information. From phpMyAdmin you can do this by selecting your database, and then clicking the search tab. Above is an example of how to search for all users under 12 years old.


In our example database this only returned one result, Peggy.




To do this same search from the query window or command line we would type in:







SELECT * FROM people WHERE age < 12



What this does is SELECT *(all columns) from the "people" table WHERE the "age" field is a number less than 12.





If we only wanted to see the names of people who are under 12 years old we could run this instead:







SELECT name FROM people WHERE age < 12



This may be more helpful if your database contains a lot of fields that are irrelevant to what you are currently searching for.




http://php.about.com/od/learnmysql/ss/mysql_data_3.htm