Odredba order by sortira redove po redosledu vrednosti iz jedne ili vise kolona navedenih u iskazu select.
Primer:
select ime, adresa
from kupci
order by ime;
Ovaj kod sacuvajte kao orderby.sql.
Objasnjenje:
Ovaj upit vraca imena poredjana po abecednom redu i adrese kupaca.
1. Otvorite phpmyadmin tako sto cete pokrenuti XAMPP. Kliknite na Admin u liniji MySQL-a ili ukucajte u address bar http://localhost/phpmyadmin
2. Izaberite bazu podataka volimmotore. Kliknite na karticu SQL.
3. Unesite kod iz fajla orderby.sql i kliknite na dugme "Go".
Primer:
select ime, adresa
from kupci
order by ime;
Ovaj kod sacuvajte kao orderby.sql.
Objasnjenje:
Ovaj upit vraca imena poredjana po abecednom redu i adrese kupaca.
1. Otvorite phpmyadmin tako sto cete pokrenuti XAMPP. Kliknite na Admin u liniji MySQL-a ili ukucajte u address bar http://localhost/phpmyadmin
2. Izaberite bazu podataka volimmotore. Kliknite na karticu SQL.
3. Unesite kod iz fajla orderby.sql i kliknite na dugme "Go".
Napomena: posto su u ovom slucaju imena kupaca u formatu ime prezime, rezultati su sortirani po abecednom redu imena.
Ako zelite da rezultati budu sortirani po prezimena, polje za ime kupca treba da razdvojite na dva razlicita polja.
Vrednosti se standardno sortiraju rastucim redosledom (od a ka z i od 1 pa navise). Ako to zelite izricito da naznacite, koristite rezervisanu rec asc, a u opadajucem rec desc.
Primer 2:
select ime, adresa
from kupci
order by ime desc;
1. Kliknite ponovo na karticu SQL i ubacite ovaj kod (koji ste prethodno dodali u orderby.sql fajl) i klik na "Go".
ORDER BY clause sorts the rows in order of value from one or more of the columns listed in the SELECT statement.
Example:
select the name, address
from customers
order by name;
Save this code as orderby.sql.
Explanation:
This query returns the names in alphabetical order and addresses of customers.
1. Open phpmyadmin by running XAMPP. Click on the Admin in line MySQL or type in the address bar http://localhost/phpmyadmin
2. Select the database lovebikes. Click the tab SQL.
3. Enter the code from the file orderby.sql and click "Go".
Note: since in this case the names of customers are in the format firstname lastname, the results are sorted in alphabetical order of names.
If you want the results to be sorted by last name, the name field of the customer needs to be separated the two different fields.
The values are sorted by default in ascending order (from a to z and from 1 and above). If you want to explicitly specify, use the keyword ASC (short for ascending), and for descending sorting use word DESC (short for descending).
Example 2:
SELECT name, address
FROM customers
ORDER BY name DESC;
1. Click on the SQL tab again and insert this code (which you previously added to orderby.sql file) and click on "Go".
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.