mysql

Mysql merge field from table to another

Hello. I want to merge the field "price" from the table "products" into the field "price" in the table "products_description". Both tables has "products_id" that match. Can't really get my head around it :( ...

Creating/importing mysql database when host doesn't allow creation of databases from script (php)

I asked similar question before and got some nice code, but i'm concerned with one of comments. I asked how to create and import mysql database from sql file in php on shared hosts. One of commenters said that some hosts might not allow me to do so from php. After digging a bit on other places someone suggested that I could create databa...

MySQL maximum memory usage

Hi, I would like to know how it is possible to set an upper limit on the amount of memory MySQL uses on a Linux server. Right now, MySQL will keep taking up memory with every new query requested so that it eventually runs out of memory. Is there a way to place a limit so that no more than that amount is used by MySQL? Thanks in advance...

MySQL Insert in table if it doesn't exist already ¿Am I doing it right?

While building my application with relational tables I ran into the following problem : I have the following table, for this example named "valores": ----------------------- | id | value | ----------------------- | 1 | Unique VAL | | 2 | Unique VAL2 | ----------------------- ID = AUTOINCREMENT VALUE = UNIQUE What I...

Difference in efficiency of retrieving all rows in one query, or each row individually?

I have a table in my database that has about 200 rows of data that I need to retrieve. How significant, if at all, is the difference in efficiency when retrieving all of them at once in one query, versus each row individually in separate queries? ...

Using multiple tables in MySQL and/or multiple columns for a Rails application

Hello, I'm wondering what the best practice is for having redundant columns in a MySQL database. I'm wondering this because I have a User table in my database but I also want to be able to display many statistics about each individual user. These stats might include how many times a user has interacted with another model or how many me...

SQL Joins in Rails

Trying to work with an existing database in rails. The below works just great in MySQL Console: select title,blog_name from exp_weblog_titles JOIN exp_weblogs ON exp_weblog_titles.weblog_id = exp_weblogs.weblog_id LIMIT 1; +------------+---------------+ | title | blog_name | +------------+---------------+ | What We Do | chicag...

Multiple SQL searches vs searching through one returned array

Is it faster to do multiple SQL finds on one table with different conditions or to get all the items from the table in an array and then separate them out that way? I realize I'm not explaining my question that well, so here is an example: I want to pull records on posts and display them in categories based on when they were posted, sa...

mysql syntax error when dealing with negative numbers

The MySQL Syntax Used INSERT INTO friend_locations (user_id, lat, long) VALUES ('82441', '28.665899', '-81.359756') The MySQL Error Returned You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'long) VALUES ('82441', '28.665899', '-81.359756')' at lin...

MySQL: Group and sum from different tables. Help!

Let's suppose we have three tables T1 ID |Type| Class | Points 111|1 |a101 | 12 111|1 |b104 | 10 112|2 |a112 | 40 118|1 |a245 | 30 186|2 |c582 | 23 T2(Data for Type = 1 only) ID |Type|EPoints 111|1 |4 118|1 |3 T3(Data for Type = 2 only) ID |Type|EPoints 112|2 |9 186|2 |15 And we want to h...

php and mysql script timeout with no errors?

Below is my code, it is a script I need to run just 1 time to update a new mysql table I have added, I have 60,000 users and it ran and added 268 rows, it did not show any errors or anything, it just didnt add the rest and I have no idea why? <?PHP require_once "../config/functions.inc.php"; // get users $sql = 'SELECT * FROM fri...

Modeling a directed graph with a special center node.

I'm looking for opinions on how to model a directed graph that contains one special node. Special node: Cannot have any edges leading to it. Cannot be removed. Current design: Tables: Nodes, Edges. Edges contains two columns; from_node_id and to_node_id, each referencing a record in the Nodes table. Rather than storing the specia...

MySQL stored procedure parameters

I want to grab x amount of items out of the DB, I was wondering if there was a way of passing some list of numbers to a stored procedure to be used with WHERE IN? SELECT item_id, item_description FROM items WHERE item_id IN ( NEED_LIST_OF_IDS_HERE ); Should I not use a stored procedure for this query and just build up the sql in the a...

Whats the proper way to check if mysql_query() returned any results?

I tried what seemed like the most intuitive approach $query = "SELECT * FROM members WHERE username = '$_CLEAN[username]' AND password = '$_CLEAN[password]'"; $result = mysql_query($query); if ($result) { ... but that didn't work because mysql_query returns a true value even if 0 rows are returned. ...

syntax error in mysql

I am trying to create a stored procedure in MYSQL. Below is my code which is giving syntax error. Can anyone please help me. CREATE PROCEDURE productpricing ( OUT pl DECIMAL(8,2), OUT ph DECIMAL(8,2), OUT pa DECIMAL(8,2) ) BEGIN SELECT Min(prod_price) INTO pl FROM products; SELECT Max(prod_price...

MYSQL errorno 121

Im getting this error in Mysql Create: Im Doing CREATE TABLE `blogReply` ( `Id` INT(24) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key of This Table', `blogId` INT(24) NOT NULL COMMENT 'Blog where this reply was posted', `userId` INT(24) NULL COMMENT 'User the blog was posted by', `n...

Python error: int argument required

What am I doing wrong here? i = 0 cursor.execute("insert into core_room (order) values (%i)", (int(i)) Error: int argument required The database field is an int(11), but I think the %i is generating the error. Update: Here's a more thorough example: time = datetime.datetime.now() floor = 0 i = 0 try: booster_cursor.exe...

Methods for merging or moving an active MySql database

I am upgrading a set of tables, adding and shifting things around. I copy all my data into the new format.... then it automatically becomes old as new data is constantly being added and changed in the old system. Without shutting down the old system for too long, is there a way to merge the two systems when data is still going into the ...

How can I further optimize a derived table query which performs better than the JOINed equivalent?

UPDATE: I found a solution. See my Answer below. My Question How can I optimize this query to minimize my downtime? I need to update over 50 schemas with the number of tickets ranging from 100,000 to 2 million. Is it advisable to attempt to set all fields in tickets_extra at the same time? I feel that there is a solution here that I'm ...

Database design -- NULL or a max value to indicate this date value?

SO I'm working on a schedule app that uses a MySQL DB. One of the modules for this site is for managers to track tardiness, overtime, and absents. The current site is a mess. It just has the manager enter in the key data, but it doesn't bind the manager to any of the already known data (like when the employee was expected to arrive/leave...