-
Posts
16,168 -
Joined
-
Last visited
-
Days Won
4
Everything posted by fenway
-
Can you give an example of what doesn't work?
-
Well, you sort of have no choice -- you have to "check" if there has been another reply by someone else -- but you don't have to check it in real-time.
-
Don't store phone number as integers.
-
Whoa... where's the JOIN condition? And don't you want a COUNT()?
-
Select all but exclude those that match data in a 2nd table from the result
fenway replied to lancia's topic in MySQL Help
You want LEFT JOIN... IS NULL. -
What's wrong with null?
-
That doesn't make any sense for a unique index.
-
Show us some sample output without all that group by stuff.
-
Form queries database for duplicates prior to completion
fenway replied to msaz87's topic in MySQL Help
Does it not have something like that built-in? Otherwise, you simply need to issue a simply query and count the number of matching rows for a given team name -- if it's > 0, then you have a dupe. -
I'm not sure I follow.
-
[SOLVED] Access denied for user 'SYSTEM'@'localhost' (using password: NO)
fenway replied to 11sven's topic in MySQL Help
Then you need a new version of the mysql libraries. -
Covers: Part 1: Using the MySQL Improved Extension, mysqli Part 2: Using the MySQL Extension, mysql Part 3: Using the PDO Extension With MySQL Driver, pdo_mysql Part 4: Using the MySQL Native Driver for PHP, mysqlnd Tutorial is here.
-
Well, a scalar subquery, that is.
-
Hopefully this presentation will stay online at scribd... it's simply fantastic, probably the best I've come across in recent memory. At 220 slides, it's quite lengthy -- but the lessons learned are invaluable, so be sure to read all the way to the end. A MUST READ!!!! EDIT: This year's version of the presentation -- some really great stuff in here, particuarly about hierarchies.
-
At the 2008 MySQL Conference and Expo, The Pythian Group gave away EXPLAIN cheatsheets (PDF).
-
This resource covers a very broad range of topics... it's worth a look, though, especially if you're stumbling in the early stages of configuration.
-
Basically, this blog contains a regularly-updated run-down of MySQL functions, with a short description and a few hints on how to use them; RSS feed here.
-
Please read the excellent FAQ thread on this issue by our very own wildteen88.
-
To ensure that your post gets answered as soon as possible, please make sure you've included the following: your MySQL server version -- absolutely required! the raw MySQL statement in question [in a CODE block, and without any PHP variables] any errors that MySQL returns to the client [from mysql_error()] the table structure & column indexes of the relevant tables [via SHOW CREATE TABLE is preferred] the EXPLAIN output for your query, if applicable a clear and concise description of what you want this statement to achieve a description of what it's currently doing that's not to your liking a brief listing of the types of things you've attempted so far If you don't provide any or all of the above, don't be surprised if your post never gets the attention it deserves. --fenway
-
You'll find a very good list of do's and don'ts written by Matt Kruse here -- highly recommended.
-
MySQL's tech resource article on database normal forms is an excellent read. NEW!!! - A large (160MB, 4M record) sample database with test suite for MySQL -- fantastic for running "real" queries. In addition, MySQL provides a number of sample databases for testing purposes; personally, I find this one to be the most useful for playing around with SQL statements and such. The Zip Code Database Project exists to provide US Zip Codes in their entirety; latitude and longitude coordinates included! The downloads are in CSV and MySQL table dump formats. Also, there's an pretty good online "data generator", and SQL is one of the options... although personally, I prefer the integers table approach (courtesy of Baron Schwartz): set @num_gamers := 10000, @num_countries := 5, @num_games := 10; drop table if exists gamer; drop table if exists game; drop table if exists country; drop table if exists score; drop table if exists semaphore; create table gamer( gamer int not null, country int not null, name varchar(20) not null, primary key(gamer) ); create table game( game int not null, name varchar(20) not null, primary key(game) ); create table score( gamer int not null, game int not null, score int not null, primary key(gamer, game), index(game, score), index(score) ); create table country( country int not null, name varchar(20) not null, primary key(country) ); -- I use the integers table to generate large result sets. drop table if exists integers; create table integers(i int not null primary key); insert into integers(i) values(0),(1),(2),(3),(4),(5),(6),(7),(,(9); insert into country(country, name) select t.i * 10 + u.i, concat('country', t.i * 10 + u.i) from integers as u cross join integers as t where t.i * 10 + u.i < @num_countries; insert into game(game, name) select t.i * 10 + u.i, concat('game', t.i * 10 + u.i) from integers as u cross join integers as t where t.i * 10 + u.i < @num_games; insert into gamer(gamer, name, country) select th.i * 1000 + h.i * 100 + t.i * 10 + u.i, concat('gamer', th.i * 1000 + h.i * 100 + t.i * 10 + u.i), floor(rand() * @num_countries) from integers as u cross join integers as t cross join integers as h cross join integers as th; insert into score(gamer, game, score) select gamer.gamer, game.game, floor(rand() * @num_gamers * 10) from gamer cross join game;
-
This page contains some in-depth, extremely well-written articles on query optimization in very common situations. A collection of fantastic resources on the subject of MySQL Performance: A Few Common Performance Mistakes - NEW! Join-fu: The Art of SQL Tuning - NEW! Basic Performance Tuning of SQL Queries and Schema/Index Strategies (FAQ) MySQL Performance Tuning - Best Practices MySQL Index Tuning and Coding Techniques for Optimal Performance MySQL Server Variables MySQL Server Variables - SQL layer or Storage Engine specific Optimizing Rank Data in MySQL Group-Wise Maximum -- doesn't really belong here, but it's an important concept anyway
-
So, for all of us who are used to "ORDER BY RAND() LIMIT 1" -- which doesn't scale well at all -- here's a "better" way. With a JOIN (concept from Jan Kneschke): SELECT * FROM tablename AS t1 INNER JOIN ( SELECT ROUND(RAND() * (SELECT MAX(id) FROM tablename)) AS id ) AS t2 ON t1.id >= t2.id ORDER BY t1.id ASC LIMIT 1; Or with subqueries: SELECT * FROM tablename WHERE id >= FLOOR( RAND( ) * ( SELECT MAX( id ) FROM tablename ) ) ORDER BY id ASC LIMIT 1 In principle, this can be extended to N rows... just remember that it's possible than <N rows are retrieved, depending on the distribution of id values -- so if it really matters that you get N back, you may want to ask for some more, just in case. Either way, you'll still have to check the size of the result set. Hope that helps.