MySQL Useful Queries
Here we show you some useful queries which you can adapt to fit your own needs.
Show the last user who signed up
"SELECT * FROM users ORDER BY 'creationdate' DESC LIMIT 1'";
Show 1 random record (user)
"SELECT * FROM userid ORDER BY rand() LIMIT 1'";
Show duplicate records (duplicate emails)
"SELECT email, COUNT(*) AS count FROM users GROUP BY email HAVING count > 1 ORDER BY COUNT DESC";
Show users who signed up today ('creationdate' = their signup date)
"SELECT * FROM users WHERE TO_DAYS(NOW()) - TO_DAYS(creationdate) <= 0 ORDER BY userid DESC";
Show users who have signed up since yesterday ('creationdate' = their signup date)
"SELECT * FROM users WHERE TO_DAYS(NOW()) - TO_DAYS(creationdate) <= 1 ORDER BY userid DESC";
Trim extra space off of email addresses in your database
"UPDATE listingsgames SET `contactemail` = TRIM(`contactemail`)";
Show timestamp as "date & time"
$timestamp=mysql_result($result,$i,"timestamp");
$dateshow = date("F j, Y", $timestamp);
echo "$dateshow"
Bookmark this page: |
Rate this page: |
Comments:
| please post comments | ||
|
admin November 21, 2006 |
||











