This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:web_development:databases:tables [2021/12/22 19:09] mag [Structure] |
en:web_development:databases:tables [2023/08/16 09:33] (current) |
||
---|---|---|---|
Line 21: | Line 21: | ||
* Above the table, you can see a menu of tabs. You're currently in the ' | * Above the table, you can see a menu of tabs. You're currently in the ' | ||
* Below that is a yellow row showing the number of rows in the result and how long it took to process. At this stage you don't need to worry about the processing time, but that can be very important for optimising complex queries. | * Below that is a yellow row showing the number of rows in the result and how long it took to process. At this stage you don't need to worry about the processing time, but that can be very important for optimising complex queries. | ||
- | * Below the yellow row is some text that says < | + | * Below the yellow row is some text that says < |
==== Fields ==== | ==== Fields ==== | ||
* Click on the ' | * Click on the ' | ||
- | * Here we see a different table. It shows how the table is structured. | + | * Here we see a different table. It shows how the data table is structured. |
* Each row corresponds to a ' | * Each row corresponds to a ' | ||
* Two of the fields have type ' | * Two of the fields have type ' | ||
Line 38: | Line 38: | ||
* Now take another look at the ' | * Now take another look at the ' | ||
* When you clicked on the ' | * When you clicked on the ' | ||
- | * It says 'show me everything in the heroes table. Let's take a closer look. | + | * It says 'show me everything in the heroes table'. Let's take a closer look. |
< | < | ||
* A query is a command to the database for information or to take an action. | * A query is a command to the database for information or to take an action. | ||
Line 46: | Line 46: | ||
* < | * < | ||
- | ==== Restricting Data ==== | + | ==== Conditions |
* This data set is currently very small, but imagine if it had every character from every Marvel film listed. It would get quite long, and we may not want to see the whole list. | * This data set is currently very small, but imagine if it had every character from every Marvel film listed. It would get quite long, and we may not want to see the whole list. | ||
* Perhaps we're only interested in the characters with magic. | * Perhaps we're only interested in the characters with magic. | ||
Line 53: | Line 53: | ||
< | < | ||
* This is very similar to the query in the ' | * This is very similar to the query in the ' | ||
- | * | + | * < |
- | * Add < | + | * In this case the condition is < |
+ | * Change the query to the following. | ||
+ | < | ||
+ | * Click the checkbox ' | ||
+ | * You can now see the table with only rows where our condition is met. | ||
+ | * We can further limit our results by using <html>AND</ | ||
+ | < | ||
+ | * Only one character is returned in the results now because only one character meets both conditions. | ||
+ | * We can also do inclusive results using < | ||
+ | < | ||
+ | * If you run this query, you should see a longer list of characters, but still not all. Now those with powers based on technology and magic are shown, but those with skill or biological powers are not shown. | ||
+ | |||
+ | ==== Sorting ==== | ||
+ | * The next useful addition to SELECT queries is being able to sort results. | ||
+ | * Imagine you're building a shopping site and want to be able to see which of your users has spent the most money so you can give them some incentives or a bonus. Sorting makes this much easier. Try the following query. | ||
+ | < | ||
+ | * We're almost there, but if we want the highest number first, we'll need to reverse the order. | ||
+ | < | ||
+ | |||
+ | ==== Limit Results ==== | ||
+ | * The last part of common SELECT queries is limiting results to a certain number. In the previous example, we wanted to reward top spenders, but we'd probably only want to do it for, say, the top ten, so there' | ||
+ | * We don't have ten rows in our result, so you won't see the effect of this unless we use a lower number. Let's try < | ||
+ | < | ||
+ | * This should give you a good understanding of tables and basic SELECT queries. In the next activity we'll look at combining results from multiple tables. | ||
+ | |||
+ | [[en: |