mysql-query

MySQL group by intervals in a date range

I am going to be graphing netflow data stored in a MySQL database, and I need an efficient way to get the relevant data points. They records are stored with the date as an int for seconds since epoch. I Would like to be able to something like: Select SUM(bytes) from table where stime > x and stime < Y group by (10 second intervals) Is ...

Why does MySQL insert 3 values instead of 1?

Hey guys, I am having trouble with what seems to be fairly easy. Let me tell you what I'm trying to do, and then I will paste in my commented code. I am trying to: Connect to MySQL Insert an incrementing value (the id) Temporarily store that value [i used mysql_insert_id()] Upload and resize an image using the class.upload.php and giv...

Empty records are inserted at each load of the web page

I am having a registration page. when the page is loaded, everytime it tries to insert the values in the textboxes which is empty by default at first. Please help. My code is attached register.template.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; <html ...

Mysql Group By Problem ?

Can someone help me with the this? This is my table structure: rec_id product_id quantity quantity_in quantity_out balance stock_date status 1 2 342 NULL 17 325 2009-10-23 1 2 2 325 NULL 124 201 2009-10-23 1 3 1 ...

Tricky query solution

Hello everyone, Does anyone have any idea on how can you create a product filtering query (or queries) that will emulate the results on this page? http://www.emag.ro/notebook%5Flaptop Explanation If you press HP as a brand, the page will show you all the HP products, and the rest of the available filters are gathered from this query ...

mySQL - One large query vs Ajax indivdual queries

Hi guys, I guess no one will have a definative answer to this but considered predictions would be appriciated. I am in the process of developing a mySQL database for a web application and my question is: Is it more efficient to make a single query that returns a single row using AJAX or To request 100 - 700 rows when the user will l...

Using a MySQL trigger to update all fields matching a condition

Hi, What I am trying to do is to set the column of each insert query to the latest value of $i I've never used a trigger in MySQL before but I do believe that's the easiest way to do this. I would be open to other ideas and suggestions. Right now I have: $i = 1; foreach($_FILES["upload_project_images"]["name"] as $key => $name) { ...

Simple MySQL query question

How would I do this (the part in square brackets): $name = 'Bob'; mysql_query("INSERT INTO table(field1,field2) [ select value of field1 from another table ], '$name'"); ...

Displaying MySQL data into HTML table (clearly explained)

Ok, I have an app as described in this post: http://stackoverflow.com/questions/1623105/good-database-structure-for-a-new-web-app I've prepared a scenario to make my question as clear as possible: Users table: +----------+-----------------+ | user_id | email | +----------+-----------------+ | user_1 | user1...

mysql distinct on 6 million rows takes 17 minutes to run? Can I speed this up?

I'm trying to get distinct id's out of a 6 million row table. The query is pretty simple, and the explain seems ok. The distict row is indexed as part of a grouped index of uid-date-time. The query is SELECT DISTINCT uid FROM events; and returns 334117 rows in 17 min 15.54 seconds. The explain is +----+-------------+-------------...

Create Select clause within Stored Procedure?

I have two tables coming which has data from two different systems. I need to reconcile the data in these two tables The column mapping needs to be made configurable. E.g.: Table A Table B Col1A, Col2A Col1B, Col2B MappingTable Col...

How can I use PHP to find a row in a MySQL DB table and insert just one value?

For example, I know I can make a new row and enter values into all fields doing this: mysql_query('INSERT INTO table_name VALUES ( "id77" ,"some value" )'); Assuming the name of the first field ("id77") is "myID" and the name of the second field ("some value") is "foo"... How can I use PHP find the row with myID = id77 and change th...

SQL and VISUAL BASIC 2008 Queries

Hello guys, How can I write a sql query that takes information from a database, and then put in the text in a label? I'm not really sure how to do this so please give me a good explanation! :) Thanks, Kevin ...

Is it possible to Update single/multiple columns using "group by".

Hi All, I am running group by on 4 columns of two tables. I have unique ID column in two tables. I want to mark both the tables occurrences column to SINGLE/MULTIPLE based on the 4 columns. Is there any way to update based on the results of group by?. ...

Lots of queries to pull up user photos and their comments. (CakePHP)

What I'm trying to do is pull up profile info w/ the profile's comments. I get everything as expected. No error returned, array is formatted perfectly. My concern is the queries that are run. It runs one query for each ID to get its photo (the start of the query is noted in comments in the code below). I guess this is the only way to get...

MySQL Query with two values matching

Howdy, I'd like to select out of one table all the entries that match two criteria SELECT * WHERE field1 IS $a AND field2 IS $b FROM TablaA something like that ... ...

MySql:Auto population

I have a table in which i have 3 columns with words.The words in col 1 have related words in col 2 and then in col3. If i select a value from the first column related words in the second column have to be displayed and in case it has related words in third column those words should also be displayed. How is this possible in mysql? ...

Select matches beginning numbers of string on integer

Hi, I have this table: CREATE TABLE `test` ( `ID` int(11) NOT NULL auto_increment, `text` varchar(250) collate utf8_unicode_ci default NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci Content: ID text 1 70-and-some-text 70 blub Then I make execute...

Updating a row in postgres from another row

I have two tables one called details and the other called c_details. Both tables are exact the same except for different table names No I a row with data in both of these tables Is it possible to update the row in details with the row in c_details Eg. update details SET (Select * from c_details)? ...

Postgres query error

I have a query in postgres insert into c_d (select * from cd where ak = '22019763'); And I get the following error ERROR: column "region" is of type integer but expression is of type character varying HINT: You will need to rewrite or cast the expression. ...