mysql

How can I get every n rows in MySQL?

I have a table which contains data recorded every minute, so I have a row for each minute. When returning the data for processing, this accuracy is required for the last 6 hours but after that, a lower level of accuracy is sufficient, e.g. every 5 minutes. I can return all the data into an array and then remove all but every 5th element...

Performance tool for MySQL

Ciao, I'm looking for performance tool for testing of load in terms of data and number of users,better if they are open source Thanks Andrea ...

php and mysql not showing data, not entering foreach loop

Hello, I am having trouble with modifying a php application to have pagination. My error seems to be with my logic, and I am not clear exactly what I am doing incorrectly. I have had before, but am not currently getting errors that mysql_num_rows() not valid result resource and that invalid arguments were supplied to foreach. I think t...

mysqli binding fields in a prepared statement

Hello, I have the following code, for which I get the error: Warning: mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement in file. If this is only a warning, shouldn't the code still work? I want to do a select * and display all the data except one field, w...

How to avoid duplicate registrations in MySQL

I wonder if it is possible to restrain users to insert duplicate registration records. For example some team is registered from 5.1.2009 - 31.12.2009. Then someone registers the same team for 5.2.2009 - 31.12.2009. Usually the end_date is not an issue, but start_date should not be between existing records start and end date CREATE TABLE...

MySQL: Getting a row number (ranking) for a specific row

I have a table for users, there's a column called money_sent. I want to order this table by money sent (most->least so DESC) and then find out which row number (ranking) a specific user is. So that I can output, User 12392 is 112/50000 people when it comes down to money_spent. Any ideas for query for this? ...

MySQL binary against non-binary for hash IDs

Assuming that I want to use a hash as an ID instead of a numeric. Would it be an performance advantage to store them as BINARY over non-binary? CREATE TABLE `test`.`foobar` ( `id` CHAR(32) BINARY CHARACTER SET ascii COLLATE ascii_bin NOT NULL, PRIMARY KEY (`id`) ) CHARACTER SET ascii; ...

Problem importing mysql procedures generated from mysqldump --routines

I use the mysqldump tool to make copies of my database. The problem is, when I use the --routines parameter to output my stored procedures along with my data, the generated output causes an error when I try to import it. It goes something like this: % mysqldump --routines MyDB | mysql MyDB2 (where MyDB2 already exists but is empty) ...

What's the best practice for storing huge amounts of text (into a DB or as a file?), and what about compressing it?

I'm building a web-app that handles internal emails and other frequent small-to-medium sized chunks of text between users and clients. What's the best method for storing this data? In a database (MySQL) or as thousands of individual files? What about compressing it (PHP's gzcompress() or MySQL's compression features)? This will not be a...

Please help me with a MySQL SQL subquery

I have two tables named foo and bar, hypothetically speaking. foo has columns foo_id, foo_fluff bar has columns bar_id, foo_id, timestamp I need a query which will retrieve return one row for any foo_id that the table bar contains, with the latest timestamp. So, if bar has three rows, two of which have a foo_id of 1, and 1 of which ha...

when to use OPTIMIZE in mysql

I have a database full of time-sensitive data, so on a daily basis I truncate the table and then import the new data (from a merge of other databases) into the truncated table. Currently I am running OPTIMIZE on the table after I have imported the daily refresh of data. However, looking at the mysql OPTIMIZE syntax page http://dev.mysq...

mysql query to get the count of each element in a column

Hi, i have a table called category in which i have main category ids and names and each main category has sub category ids and names.i also have a product table with a category id column which either has a numeric sub category id or a 2 letter main category id eg:EL for electronics..my problem is how to get top categories ie., number of...

MySql getting count of each type of element in a cloumn

Hi, I have 2 tables with the following structure.. category { sub_cat_id - numeric sub_cat_name - varchar main_cat_id - varchar (2 characters) main_cat_name - varchar } products { pid - autoincrement pname - varchar category (Will be either sub_cat_id or main_cat_id) } Products table pid pname category 1...

Select data according to manager & employee level in mysql

Table structure is like this - id Name Manager 1 aa NULL 2 hh 1 3 YY 4 4 Kk NULL 5 PP 4 So I want the result like- Name Manager aa NULL hh aa Kk NULL YY Kk PP Kk ...

Simple SQL problem (MySQL)

Hey, I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON page.id = revision.pageId Which will return something like: "1" "Page Version A" "1" "1" "Page Version B" "2" "1" "Page Version C" "3" Now I only want to return one row for each page, with the data from the late...

mysqli problem - prepared statements

Hello, I have the following snippet of code from my application, which should work. However, i get the error that: Warning: mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement in file. I am using the exact number of columns to bind as to select, and using l...

Selecting a database in mysql with spaces in its name

I want to select my particular database in mysql console, but the problem is that my database name has a space in between and mysql ignores the part after the space. For instance, when i give the command: use 'student registration' I get the message: cannot find database 'student' ...

MySQL sorting the result using a field of a different table

I have 3 tables of the following structure products { pid pname plocation... } services { s_id s_name s_location... } txn { tid pid... } I am using the following query to get the values I require. $dbquery = "SELECT DISTINCT prod...

mysql formatting a date

Hello I am trying this query: SELECT ARTICLE_NO, USERNAME, ACCESSSTARTS, ARTICLE_NAME, date_format( ACCESSSTARTS, '%d %m %Y' ) AS shortDate FROM AUCTIONS WHERE upper( ARTICLE_NAME ) LIKE '%hardy%' LIMIT 0 , 10; Which works fine, but shortDate is null, and I am unsure why. The contents of the database is like s...

How do I suppress the row count for tables added (AUTO_INCREMENT=N) to mysqldump output?

I use the following command to output the schema for a MySQL db: mysqldump --no-data --skip-add-drop-table I will do this for two databases I want to compare, and then diff the two output files. This is my crude way of tracking database changes between environments. However, a minor inconvenience to me is that the row count for each...