mysql

User options in another table: what is the best practice to check if an option is there?

I have several option that a user can have, mainly to validate his presence around the site. Tables are like this: Users: id=1 username=stackoverflow password=oSKAJMMS; address=xyz ... Options: user_id=1 option=AD3 user_id=1 option=AC1 At some point I need to check if he has a particular option (like: AD3, AC1 etc) in the "op...

Are LEFT JOIN subquery table arguments evaluated more than once?

Hello. I have a query that looks like this: SELECT * FROM employees e LEFT JOIN ( SELECT * FROM timereports WHERE date = '2009-05-04' ) t ON e.id = t.employee_id As you can see, my LEFT JOIN second table parameter is generated by a a subquery. Does the db evaluate this subquery o...

Store form data in MySQL with jQuery.ajax

Edit: I found the soluton for getting the correct URL. Se the solution in this thread. Hi, I'm having problems prosessing a form so that I can save it's data in my MySQL database. I'm using Wordpress as CMS. I've used this example: http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form I'm pretty sure that the source of my p...

Does MySQL collation type need to match PHP page charset type?

I have started debugging my RSS feed because it has some strange characters in it (i.e. the missing-character glyph). I started with two excellent beginner resources: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets: http://www.joelonsoftware.com/articles/Unicode.html Chara...

how to manage sql structure updates

How do people recommend managing database structure updates? e.g. new features are added that require existing tables being altered, new ones added etc. Is there a good piece of software or is it a case of writing ALTER type statements. ...

How do i update mysql database with ajax and php in innerhtml

How do i update mysql database with ajax and php with no page refresh ...

MySQL Support for Python that's not under GPL-Like Licenses

Hello, I'm using Python/Django over MySQL. I'm currently working with MySQLdb that's under GNU GPL license. Is there a library with "similar" capabilities that's not under GPL-like licenses? To clarify: I don't know yet if I will want to distribute my source code or charge money for my application. What I do know is that I don't want...

How to find a first column and first row in a table using SQL

I was asked this question and could not come up with the answer. Is there a way to find the entry at the first row and first column in a table? (In matrix notation, that would be the [1,1]th location) ...

How many MySQL database can be created in a single domain in Plesk control panel?

Do you have any experience about this question? I have currently 1900 MySQL databases in a single domain in my plesk control panel and I wonder if my MySQL server gets overloaded or out-of-service due to such high number of databases in the system. Do you have any suggestions? Each database is for a user in my service by the way. ...

Problems with contenttypes when loading a fixture in Django

I am having trouble loading Django fixtures into my MySQL database because of contenttypes conflicts. First I tried dumping the data from only my app like this: ./manage.py dumpdata escola > fixture.json but I kept getting missing foreign key problems, because my app "escola" uses tables from other applications. I kept adding addition...

Find duplicate records in MySQL

I want to pull out duplicate records in a MySQL Database. This can be done with: SELECT address, count(id) as cnt FROM list GROUP BY address HAVING cnt > 1 Which results in: 100 MAIN ST 2 I would like to pull it so that it shows each row that is a duplicate. Something like: JIM JONES 100 MAIN ST JOHN SMITH 100 MAIN...

How can I write a query that excludes certain results, but includes results that lack the association used for exclusion?

I have a search form used to query service provisions, which I will call 'provisions'. Provisions may have certain eligibility requirements in a has and belongs to many relationship, but they may also have no requirements at all. My issue is that when I exclude certain provisions on the basis of a particular requirement, those provisio...

Is there a way I can make the CASE WHEN test one of the results rather than running it twice?

Is there a way to use the value from the CASE WHEN test as one of its results without writing out the select statement twice (since it could be long and messy)? For example: SELECT id, CASE WHEN ( (SELECT MAX(value) FROM my_table WHERE other_value = 1) IS NOT NULL ) THEN ( SELECT (MAX(value) FROM my_ta...

Process many incoming emails in Rails: MySQL vs. Imap / Pop3 vs. other solution

Hi, at an application I'm working on users can forward their email-accounts to an address from our system (something like [email protected] ). It doesn't matter here why they should do this, but I need some professional advice on the best way to approach this. The basic idea is that our mailserver receives the incoming (for...

Password hash and salting - is this a good method?

I was doing a little research or googling for different methods of handling password hashing and salting and came across this interesting link: http://phix.me/salt/ Now, essentially what this proposes is the creation of two user functions, one for hashing and one for checking the hash. The salt is pseudo random but is in actual fact ...

Randomly long DB queries/Memcache fetches in production env

I'm having trouble diagnosing a problem I'm having on my ubuntu scalr/ec2 production environment. The trouble is apparently randomly, database queries and/or memcache queries will take MUCH longer than they should. I've seen a simple select statement take 130ms or a Memcache fetch take 65ms! It can happen a handful of times per request,...

Best practice for keeping denormalized schema up to date?

I'm creating a game with points for doing little things, so I have a schema as such: create table points ( id int, points int, reason varchar(10) ) and to get the number of points a user has is trivial: select sum(points) as total from points where id = ? however, performance has become more and more of an issue as the points...

Strange Exception on getGeneratedKeys() with JDBC for MySQL 5.1

Hello, I'm using JDBC to insert a row into a MYSQL database. I build a parameterized command, execute it and attempt to retrieve the auto generated keys as follows: String sql = "INSERT IGNORE INTO `users` (`email`, `pass-hash`) VALUES (?, ?)"; Connection conn = SQLAccess.getConnection(); PreparedStatement ps = conn.prepareStatement(...

How do I merge two partially overlapping lists in MySQL?

OK, so I have two tables (views actually) that both have the same structure. Each has a column with a date and a column with a numerical value. The dates in both tables will be almost continuous and cover the same period. The data will consequently be largely the same, but a date in one table may not appear in the other. I want to have...

Is a primary key required in this particular scenario?

I have a name table with (id,first_name,middle_name,last_name,sex) and an email table with (id_fk,email_add) Infact I will be having similar tables of the second kind, like a phone table (id_fk,phone_no), where id_fk is the foreign key referring to the id in the name table. Is it required or rather is there a good reason to have a prim...