mysql-query

MS SQL Server 2005 GROUP BY and SUM

Hey all, i am trying to create a report to show how much is spent per HRCode. This is my SQL Query so far: SELECT * FROM tblWO as WO, tblWOD as WOD, tblWA as WA WHERE WOD.OrderID = WO.ID AND WA.HRCode = WO.AdministratorCode AND WO.OrderDate BETWEEN '2010-01-01' AND '2010-08-31' AND Approved = '1' ORDER B...

Why am I getting "Unknown Column" error?

The exact error I am getting is: "Unknown column 'trans_paid' in 'where clause'" My query ($from_date and $to_date are correctly formatted): SELECT o.order_id, o.order_po_no, o.order_ship_date, acct.acct_company, SUM( ROUND( i.item_qty * i.item_price, 2 ) ) AS item_amount, ( SELECT SUM( trans_amount ) FR...

Mysql JOIN of four tables with two key tables

I hate to admit it by my knowledge of MySQL is lacking when it comes to the more complex queries. Essentially I have four tables two of them contain the data I want to return, and two are relational tables linking the data. Table A is present just to provide filler for Table D.aID. +--------+ +--------+ +--------+ +-----------+ +------...

howto make such a mysql query?

hi there i want to design a football result table from a existing database structure. TEAM(id, name) GAME(id, team1id, team2id, goalsTeam1, goalsTeam2) the result table should look like: name games points name games points name games points (the points can be get by looking who hase make more goles (win=3,draw=1,loose=0)) i dont k...

SQL UPDATE not working?

In my LAMP application (using CodeIgniter), I have a call to $this->db->update... that generates a SQL like the following: UPDATE `MyTable` SET `MyProcess` = 5 WHERE `Id` = 1 The problem is that this seems to work intermittently -- and I currently have no idea what might be wrong. Is there anything about MySQL I need to know about whe...

Insert php value into mysql table

https://docs.google.com/document/edit?id=1dL_Q2dAo4DuyaS9rVGM5tVPXW8vWZYOvrcfSbnOD-uk&hl=en $num = $_GET['p']; echo "Number: ".$num." Other: ".$Other; ?> How to insert ".$num." into mysql_query("UPDATE `grass` SET `$num`='{$_POST['c2']}' "); } ...

mysql query sum based on years

i friend i have a database table amount_id, year, amount, and data like this 1 2002 2 2 2002 3 3 2007 2 4 2004 6 5 2004 10 i wan to run a query to select data like this 2002 4 2007 2 2004 16 thanks for help ...

simplifying a MySQL query, pulling table name dynamically from table data

Hello I have a mysql table and one of the fields is 'template'. This field will point to the correct template table to reference the unique fields for that particular template. So for example if table.template = 'news', I also need to pull the info from the news_template table to have the complete set of listing info. Right now I only...

JPA: how to make a field auto increment

I use Eclipselink as my JPA provider, how can I make a field auto increment? ...

mysql inner join on self, matching previous record

Hello, I have a database of transactions, mapped by a parameter called flaglessContractID. Among those, there are cp_flag which may be either 'ca' or 'pu'. I am trying to get in 1 query a result set which contains on a row a transaction price (PRC_O and PRC_C) and also the previous transaction on that contract (flaglessContractID is the ...

Mysql slow query: JOIN + multiple WHERES + ORDER BY

Hello all, long time lurker, first question! I am struggling to optimize this query, which selects the lowest priced items that match the chosen filters: SELECT product_info.*, MIN(product_all.sale_price) as sale_price, product_all.buy_link FROM product_info NATURAL JOIN (SELECT * FROM product_all WHERE product_all.date = '2010-09-30')...

On submit from textarea - mysql error

Hello! I am using TinyMCE on my new site in english, that I am doing by myself (I am like a sunday programmer :) ). As before I was doing sites in my native language, I did not get this problem: So... when i write in the textarea a word " don't " or " doesn't " the " ' " breaks the MySQL querry and I get an error about MySQL syntax. I...

Simple SQL question - pulling value between min and max

Okay, this is probably really simple but for some reason I'm totally fried on this and need some advice. I have two columns in my database, budget_min and budget_max. Oh the front end, I'm trying to build a search that will find everything between two budgets, say 1000 - 2000, or 2000 - 4000. Need something like where budget_min > 100...

Printing all the queries that mySql generates

I work with Workbench and phpMyAdmin with mySql, I use Procedures and Function etc... Sometimes one procedure triggers another Function and so on... eventually something goes wrong somewhere. Is there any tool known to anybody that can show all the queries mySql runs? Like a command prompt that shows every command MySql runs it would b...

is this the correct way to optimize MySQL Query?

$sql="update users_contain set wood_max = (Select building_production from building_level where merge_id=$subPrimaryKey and empire_id=$user_empireID) , iron_max = wood_max, clay_max = wood_max where user_id = $user_id"; Now there is a question. will wood_max will always be updated first than iron_ma...

The stored procedure in the query

There is a procedure GetFileList - returns, as the name implies, a list of files and a couple more options with them. Is it possible then to use this procedure in the query select? Something like this: select Field1 from Image where Field2 IN (call GetFileList ()); ...

Putting an index on a date field in MySQL

Is there going to be any real benefit to me putting indexes onto date fields that are going to be mainly used in queries using stuff like. dateField < 'var' And 'var' BETWEEN dateField1 AND dateField2 The searches get done a lot but I am never doing a direct comparison "=" on them. ...

Distinct in the cursor does not work...?

Hello ... Prompt, something I can not understand, distinct in the cursor does not work or what? have a cursor with a distinct, which I get around in a loop .. If the request from the cursor to perform separately, then returns 1 record, if distinct clean, there will be 2 entries. A loop through the cursor with distinct runs 2 times. DECL...

Why is my query not using this index?

I have a query I turned into a view that works OK. But the site_phrase sp table seems to be not using a column and goes through all the records in the table. Why is that? Here is the query: EXPLAIN SELECT `p`.`id` AS `id`, `p`.`text` AS `phrase`, `p`.`ignored` AS `igno...

Building an index table from a MySQL database with PHP

Using MySQL and PHP; I'm trying to build an index that contains the averages from table_1 grouped by: type, name, hour, day, month, year So I need to know which combination's of values are in table_1 so I know what to put in my AVG() queries. What I want is to figure out all the different combination's that can be made when comparing ...