Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
/VM/station wiki
Search
Search
Log in
Personal tools
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
MySQL
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Filter rows === Well, now that we managed to isolate a few columns, let's see about filtering through rows. We'll return to selecting all columns tho. Conditions for which rows you want returned and which you don't are defined in the WHERE portion of the SELECT statement. ==== Strings ==== Execute this: SELECT *<br> FROM ss13_player<br> WHERE lastadminrank = "Player" This will return a list of people, who have their 'lastadminrank' column set to "Player". '''Note the single =''' So no admins will be in the returned list. So how do we get admins? Simple. SELECT *<br> FROM ss13_player<br> WHERE lastadminrank != "Player" As you know != means "not equal". It is however case sensitive. It also doesn't allow you to do any clever filtering. Let's look at LIKE: ==== LIKE ==== SELECT *<br> FROM ss13_player<br> WHERE ckey LIKE "%abc%" This will return a list of players, whose ckey contains the letters 'abc'. The % signs before and after abc mean that anything can be located before or after abc. LIKE also ignores case, so all of the following will work: "'''abc'''n", "aocwegijaw'''abc'''maobr", "'''abc'''", "'''ABC'''", "'''AbC'''", "E'''Abc'''", "aWAEGaewgaWEG'''aBc'''aegawe". Your example might require you to replace the string abc with a different character combination, depending on which ckeys you have logged. ==== Numbers ==== Numbers use what you'd expect. >, >=, <=, <, =, != SELECT *<br> FROM ss13_player<br> WHERE id < 50 will return all lines where the id is lower than 50. ==== Date and time ==== The ss13_player table contains two fields which are of type 'datetime': firstseen and lastseen. You can compare them directly with >, <, =, !=. '''Note the single ='''. For example: If you want to only select people who have only logged in once, and then never again: SELECT *<br> FROM ss13_player<br> WHERE firstseen = lastseen ===== DATE() ===== You can however also select people who were first seen on a particular date. You'll need to use a function for that tho: SELECT *<br> FROM ss13_player<br> WHERE DATE(firstseen) = "2013-04-19" This will return a list of players who were first seen on 19 April 2013. If you want to get people who joined after April 17 2013, execute the following: (NOTE, This will only show people who joined on 18 April or later! Use >= if you want to include 17 April.) SELECT *<br> FROM ss13_player<br> WHERE DATE(firstseen) > "2013-04-17" ===== DATEDIFF(), NOW() ===== Okay, so now you know how to select people who joined after a constant date. But what about if you want to only select people who joined in the last 7 days? The date keeps changing all the time, the date in the select statement, however, remains the same. The fix is pretty easy: SELECT *<br> FROM ss13_player<br> WHERE DATEDIFF(Now(),firstseen) < 7 This will select everyone who joined 7 or fewer days ago.
Summary:
Please note that all contributions to /VM/station wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
/VM/station wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width