The community is working on translating this tutorial into German, but it seems that no one has started the translation process for this article yet. If you can help us, then please click "More info".
If you are fluent in German, then please help us - just point to any untranslated element (highlighted with a yellow left border - remember that images should have their titles translated as well!) inside the article and click the translation button to get started. Or have a look at the current translation status for the German language.
If you see a translation that you think looks wrong, then please consult the original article to make sure and then use the vote button to let us know about it.
Please help us by translating the following metadata for the article/chapter, if they are not already translated.
If you are not satisfied with the translation of a specific metadata item, you may vote it down - when it reaches a certain negative threshold, it will be removed. Please only submit an altered translation of a metadata item if you have good reasons to do so!
MySQL and the WHERE part
In the previous chapter, we saw how we could use the SELECT query to get data from the database, but we weren't exactly very picky about which data to get. As you will realize in the following chapters, the SELECT statement is very powerful and allows you to do pick, prioritize and sort your data in all sorts of way before returning it. In this chapter we will have a look at the WHERE part, which allows you to decide which data to select.
An SQL statement with a WHERE part could look like this:
SELECT id, name, country FROM test_users WHERE id > 3
You can of course set more than one criteria:
SELECT id, name, country FROM test_users WHERE id > 3 AND id < 8
And you can use strings as criteria as well:
SELECT id, name, country FROM test_users WHERE country = 'USA'
You can even use MySQL's own functions in the WHERE part. For instance like this, where we use the SUBSTRING() function in MySQL to get all users starting with the letter "S":
SELECT id, name, country FROM test_users WHERE SUBSTRING(name, 1, 1) = 'S'
To test the examples above, you can use this test code we wrote in a previous chapter. Simply put one of the queries inside the mysql_query() function and run the code:
mysql_connect("localhost", "username", "password"); mysql_select_db("my_database"); $query = mysql_query("Insert your SQL query here"); while($row = mysql_fetch_array($query)) echo $row["name"] . " is from " . $row["country"] . "<br />";