Saint
New Member
Hello,
I have no idea whether tutorial like this was created or not, anyway I will show you how to quickly find a player in large database. We will use simple SQL queries.
Why did I write it?
Well, I remember when I was starting with SQL servers. Whenever I had to find player I was really angry, because I had to browse whole database to find him. Time passed and I learned SQL a bit and I decided that I'll try to help people who just started with SQL servers.
Step 1 - we are starting!
I assume that you already have an otserver and database. Go to 'players' and click SQL button. You'll see what's on screen below.
Step 2 - simple searching!
Now it's time to write your first SQL query to find certain player!
Now I'll explain what we've done.
SELECT - this statement is used to select data from database.
SELECT * - it selects EVERYTHING
'players' - it's table's name
WHERE - clause is used to select data conditionally, by adding it to already existing SELECT query
WHERE NAME = "Nickname" - there's no need to explain, right? ;-)
LITTLE TIP!
You don't have to write manually column's names. You can use this little box and double click on name you wanted.
Step 3 - and what if we want to sort players by levels?
Well, it's simple, lets go!
What does ORDER BY 'level' DESC mean? It sorts player from highest level to smallest. If you write it without 'DESC' it'll sort from smallest to highest. It's easy, isn't it? ;-)
Step 4 - useful queries (for lazy people)
Sort players by magic level
Last logged players
I hope this will help. If it helped you, I'd be thankful if you rep++ me. This should motivate me to write more tutorials! ;-)
Yours,
Damian.
I have no idea whether tutorial like this was created or not, anyway I will show you how to quickly find a player in large database. We will use simple SQL queries.
Why did I write it?
Well, I remember when I was starting with SQL servers. Whenever I had to find player I was really angry, because I had to browse whole database to find him. Time passed and I learned SQL a bit and I decided that I'll try to help people who just started with SQL servers.
Step 1 - we are starting!
I assume that you already have an otserver and database. Go to 'players' and click SQL button. You'll see what's on screen below.
Step 2 - simple searching!
Now it's time to write your first SQL query to find certain player!
Now I'll explain what we've done.
Code:
SELECT * FROM `players` WHERE NAME = "GOD Ashri on Nahgor"
SELECT - this statement is used to select data from database.
SELECT * - it selects EVERYTHING
'players' - it's table's name
WHERE - clause is used to select data conditionally, by adding it to already existing SELECT query
WHERE NAME = "Nickname" - there's no need to explain, right? ;-)
LITTLE TIP!
You don't have to write manually column's names. You can use this little box and double click on name you wanted.
Step 3 - and what if we want to sort players by levels?
Well, it's simple, lets go!
Code:
SELECT `name`,`level`
FROM `players`
ORDER BY `level` DESC;
What does ORDER BY 'level' DESC mean? It sorts player from highest level to smallest. If you write it without 'DESC' it'll sort from smallest to highest. It's easy, isn't it? ;-)
Step 4 - useful queries (for lazy people)
Sort players by magic level
Code:
SELECT `name` , `level` , `maglevel`
FROM `players`
ORDER BY `maglevel` DESC ;
Last logged players
Code:
SELECT `name`,`lastlogin`
FROM `players`
ORDER BY `lastlogin` DESC;
I hope this will help. If it helped you, I'd be thankful if you rep++ me. This should motivate me to write more tutorials! ;-)
Yours,
Damian.