mysql

[Database design] Optimize database for search (and interpolation of search values)

Hello, I have a relatively large database tables (just under a million rows) that has mapping like this: (int, int, int, int) ----> (float, float) Not all possible int combinations map to a float pair. Here is where my knowledge of database design ends: The database size is not a concern for me, but query time is. Should I worry ab...

Flex App getting data from MySql via PHP - Examples

Hello guys. I'm learning Flex, I already know how to submit data from a Flex App to a MySql DB using PHP. But thats easy, but getting data... Thats a different story. This isn't a question for sort of speak, its a request. I wanted to ask to everyone that already learned how to do this, if it could send some Flex Projects (the ones yo...

Site wide search on a rails application

Hi, I'm trying to add search capability to one of my rails applications. I just need it to search through the mysql columns of quite a few models well. I'm wondering what the best way to do this is. I figure I should use a plugin but I don't see anyone really recommending one over another. Is there one you would recommend over all ot...

Add a cell from two or more rows in the same MySql table

I have x rows of a column value and "simply" want to add them together and update the highest row number and zero out the other values: SELECT rowId, addCol FROM table WHERE rowId=1 OR rowId=2 rowId | addCol 1         | 100 2         | 200 3         | 67 This is kind of what I want (I know it's completely wrong) but not sure how to ...

I need help fixing Broken UTF8 encoding

I am in the process of fixing some bad UTF8 encoding. I am currently using PHP 5 and MySQL In my database I have a few instances of bad encodings that print like: î The database collation is utf8_general_ci PHP is using a proper UTF8 header Notepad++ is set to use UTF8 without BOM database management is handled in phpMyAdmin not al...

Get MySQL Cell in shell script

I would like to execute a MySQL command in a shell script/cron job that returns a dynamic number of rows in which I can access a specific field from those rows. I would then like to loop through this performing additional commands on those field entries. My two questions then are: How do I return a set of rows (ideally just a single ...

MySQL Selecting count

I have two tables: codes_tags and popular_tags. codes_tags CREATE TABLE `codes_tags` ( `code_id` int(11) unsigned NOT NULL, `tag_id` int(11) unsigned NOT NULL, KEY `sourcecode_id` (`code_id`), KEY `tag_id` (`tag_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 popular_tags CREATE TABLE `popular_tags` ( `id` int(10) unsigned DEFAULT NU...

Help me build this MySQL Query

this should be easy, but it's not :( I have a table with a bunch of different feature Ids. What I need is to build a way to say: "show me all pet stores that have puppies, kittens, mice, or fish" (at least one) That's the easy part. What I'm stuck at is... "show me all pet stores that have puppies for sure, but maybe also kittens...

get max value in php (instead of mysql)

I have two msyql tables, Badges and Events. I use a join to find all the events and return the badge info for that event (title & description) using the following code: SELECT COUNT(Badges.badge_ID) AS badge_count,title,Badges.description FROM Badges JOIN Events ON Badges.badge_id=Events.badge_id GROUP BY title ASC In addit...

MySQL Function to return table name to be used in a query

Can I use a MySQL function or procedure to return table names that can be used in a query? Something like SELECT * FROM get_db_table_name(2342352412); where get_db_table_name() is a user defined function which accepts a user_id as a parameter and returns the db.table where that user resides. I have not been able to do this this way be...

mysql lock wait timeout exceeded, try restarting transaction

Hi All, I am getting following error while I am trying to execute a stored procedure which has one update statement. Below is the INNODB STATUS OUTPUT after the error: ===================================== 090828 12:54:36 INNODB MONITOR OUTPUT ===================================== Per second averages calculated from the last 33 secon...

What is the difference between utf8_general_ci and utf8_unicode_ci in MySql?

Are there any big differences a developer should care about? ...

GROUP BY Optimization [MySQL]

Hey. I´ve got these two tables in a 1:n relation. CREATE TABLE IF NOT EXISTS `de_locations` ( `id` int(11) NOT NULL auto_increment, `user_id` int(11) default NULL, `author_id` int(11) NOT NULL, `city_id` int(11) NOT NULL, `district_id` int(11) NOT NULL, `title` varchar(150) collate utf8_unicode_ci NOT NULL, `description` tinytext collat...

How to SUM from MySQL for every n record

I have a following result from query: +---------------+------+------+------+------+------+------+------+-------+ | order_main_id | S36 | S37 | S38 | S39 | S40 | S41 | S42 | total | +---------------+------+------+------+------+------+------+------+-------+ | 26 | 127 | 247 | 335 | 333 | 223 | 111 | 18 | 1394 | ...

Do I need to synchronize if I have multiple threads that will insert to MySQL?

I'll be using a multi-threaded Java program to insert new records to a table in MySQL. Is it necessary to synchronize for this? Or is it OK since each insert is a different record in my case? ...

Collation Issue

Hi If I change the table type default collation to UTF8 from latin does it slow down the queries? ...

MySQL: Count occurances of distinct values

Hi, I am trying to find a MySQL query that will find distinct values in a particular field, count the number of occurrences of that value and then order the results by the count. example db id name ----- ------ 1 Mark 2 Mike 3 Paul 4 Mike 5 Mike 6 John 7 Mark ...

What does DELIMITER // do in a Trigger?

DELIMITER // What is the of use of it? ...

Force mysql to return no result on bit_or

I have a mysql query that uses bit_or on a result set. When there is no result set, the bit_or function returns 0 (this is correct as per the mysql documentation). For example: select n from t1 where a=1; Returns no rows. select bit_or(n) from t1 where a=1; Returns 0 I need to force the last query to instead return no result from...

Unique constraint that allows empty values in MySQL

I have a field that stores product codes. The codes are unique, but some products simply doesn't have a code. I can't invent codes because those are providers codes. Is this kind of constraint possible in MySQL? I'm a noob with stored procedures and triggers, so if the solution involves one of these, please be patient. Update: The col...