Update Syntax For Multiple Columns
I'm looking for a feature I'm accustomed to with other SQL products, whereby multiple columns can be updated with a single SET clause, e.g.:
UPDATE tab1 SET (col1, col2, col3) = (SELECT col4, col5, col6 FROM tab2 WHERE tab2.col1 = tab1.col1);
I don't see this feature documented for MySQL. Is there a way to accomplish it?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Update Multiple Columns
I get an error on this command: UPDATE patchMapTable SET row=0,column=0,patchNumber=23 "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 'column=0,patchNumber=23' at line 1" row, column, and patchNumber are columns in patchMapTable all 3 are int row and column are primary keys
Select / Insert Multiple Rows As A Single Row Of Multiple Columns
I have a nice database set up that contains information about orders and the items on those orders. If an order has 10 items on it, I can select the item data which returns 10 rows of data (let's say 5 colums each). Beautiful! Now I find myself needing to satisfy a program that requires all of the data on a single row. I can do this in a higher level language, but if I could accomplish it all in mysql it would be better. I don't need to sum or do any calculations. I just want to select those 5 columns of data about those 10 rows worth of items as a single row with 50 columns. For example, I'd want this: 1-1,1-2,1-3,1-4,1-5 2-1,2-2,2-3,2-4,2-5 To become: 1-1,1-2,1-3,1-4,1-5,2-1,2-2,2-3,2-4,2-5 The first complication is that the number of items on an order is variable, but is always at least 1 and can not exceed 20. The closest I've been able to get is to do something like: SELECT GROUP_CONCAT(item_number,",",qty,","",description,"",",price,",",location_number SEPARATOR ",") FROM items WHERE order_number=12345 This will give me a single text string containing the value content of the INSERT query (which will need to be manipuated outside of the SQL query to pad it with NULL values for the unused items' columns etc).
MIN() Over Multiple Columns
I need to find out how to find the minimum value usig a query over three columns: SterlingTradeGross BlowOutNett SterlingTradeQGross These are the three columns, I need a query which calculates the minimum value from all of these, how do I do it?
WHERE With Multiple Columns
I have three tables: person with per_id, event with eve_id and than third table per_eve with the two columns per_id and eve_id. I now need to check, if a row exists in the per_eve-table for a certain event and person. If there is an occurence, than I don't want that row in my overallresult. Which person and event to take I get from other conditions. To check for non-existence I thought something like "WHERE (person.per_id, event.eve_id) != (per_eve.per_id, per_eve.eve_id)" could give me all rows not to drop, as I need the combination of both values. But it does not work, I get an errormessage after the first comma.
Where In Multiple Columns
I am attempting to search multiple columns for the same foriegn key. I have the following columns in my catalog_images table: nID, strFileName, nCategoryA, nCategoryB, nCategoryC, nCategoryD, nCategoryE and I want to select strFileName from catalog_images where ANY of the following matches occur: nCategoryA="1", nCategoryB="1", nCategoryC="1", nCategoryD="1", nCategoryE="1" I can't figure out my query string. Any suggestions?
STD Of Multiple Columns
I want to calculate the standard deviation of data that are in multiple columns. I know how to calculate the STD of 1 column (e.g. X1 of table_X) using: SELECT STD(X1) FROM table_X; but I want to calculate now the STD of the union of data of columns (e.g. X1, X2, ..., X100 of table_X). Does anyone has any suggestion on how to do that? I hoped something as SELECT STD(X1,X2,...,X100) FROM table_X existed, but apparently it does not.
Multiple Columns
I did a search and could not find what I was looking for. Hopefully someone can answer this. I am trying to SELECT multiple columns as one column for display. Something like this (which obviously does not work): Quote: SELECT column1 as combinedlist, column2 as combinedlist FROM `myTable` WHERE column1='data1' OR column2='data1' ORDER BY combinedlist I have also tried: Quote: SELECT (column1, column2) as combinedlist FROM `myTable` WHERE column1='data1' OR column2='data1' ORDER BY combinedlist
Multiple Columns
How do I query a table in order to combine ST_ADDRESS, CITY, STATE, ZIP fields into one ADDRESS field?
Help With Update Syntax
This is a fairly common task, but for some reason I'm blanking and haven't had any luck with the manual. What I want is a query that tries to update a record on a table, or if the record doesn't exist it inserts it. Is there a single query way to accomplish that?
Update Syntax Help
I am UPDATING a profile table based on $id and $company_id. $id = 10 $company_id = 500 profile: p_id, company_id, client_id 10,50,100 20,40,80 30,60,120 My update statement looks like this.. PHP UPDATE profile SET company_id = '$company_id' WHERE p_id = '$id'"; UPDATE profile SET company_id = ņ' WHERE p_id = ཆ'"; But I have another table I need to update called user2company which has records than correspond to the user table. These records in user table doesnt change. user: increment_id,profile_id,login_id,password 1,10,joe,pass1 2,10,mary,pass2 3,20,sam,pass3 4,30,bill,pass4 user.profile_id is linked to profile.p_id user2company: id, company_id 1,50 2,50 3,40 4,60 user2company.ID is linked to user.increment_id Now how to I update my user2company.company_id when my profile.company_id changes for only the condition p_id = 10? Final result: profile: id, company_id, client_id 10,500,100 20,40,80 30,60,120 user2company: id, company_id 1,500 2,500 3,40 4,60 I tried an UPDATE syntax but what happens is that all of my records in user2company.company_id changes to 500
Update Syntax
I have an autoincrement table with about 32 columns. (mysql5) The first column is the auto incrmenting index. I need to retrieve a row from the table, update multiple fields in the row and write the row back to the table with the same index. I have read the manual but (newbie) don't understand how to do this.
UPDATE Syntax
I'm having problem with an UPDATE syntax. I want to update 2 fields from a certain record in a table. The following syntax works: UPDATE items SET price='30' WHERE num='1' BUT When I try to update 2 fields using the following syntax I get an error saying that my syntax is wrong. UPDATE items SET desc='cheese',price='30' WHERE num='1' What's wrong with it?
UPDATE Syntax
I am running Apache version : Apache/1.3.33 (Win32), PHP version : 5.0.4 and MySQL version : 4.1.10a-nt - extension : mysqli on my home computer. When I execute the following SQL it works fine. UPDATE places SET places_count = (SELECT COUNT(*) FROM joins WHERE joins.pid = places.pid) However, when I try to run it on my hosted site which uses Apache version : Apache/1.3.33 (Unix), PHP version : 4.3.11 and MySQL version : 4.0.25 I get the following error. MySQL said: #1064 - 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 'SELECT COUNT(*) FROM joins WHERE joins.pid = places.pid)' at li
UPDATE Syntax
What if I use UPDATE blablabla WHERE blablabla but there actually isn“t a row in the table that would fit the WHERE statement? Does it just ignore it or does it screw it up? Also if i use the same syntax and there is a lot of records that fit the WHERE statement, how can I limit it so that it only updates one row.
Update Syntax
well i know the update syntx and i am using this: Update SilverProducts set id = 'sl209', set category = 'Anklets', set description = 'anklets', set price = '29.99', set weight = '12', set diameter = '25' where id = 'sl209' however i get an error saying something wrong near "set category..." line? but i cant figure out what
Update Syntax
I am having some trouble with an update query: update mytable set field_a='test', field_b='test2' where uid=(select uid from mytable where time='09:00' and field_a is NULL order by uid limit 1) I get the error Quote: You can't specify target table 'mytable' for update in FROM clause I can understand why I get this error but what can I do to fix this? Here's what I am trying to do: I have a table to sign up people and there can be 3 entries per timeslot. In the beginning, the table has entries for each time slot with field_a and field_b set to NULL. When a user signs up for a time, I want to put them into the first available slot for that time.
UPDATE SQL Syntax
I need to do an Update that involves writing to table tblDateLog based on the values in tblConcess as follows CODEUPDATE tblDateLog, tblConcess SET tblDateLog.OpenEarly = [EndDate] + [DefOpenEarly], tblDateLog.DataDueIn = [EndDate] + [DefDataIn], tblDateLog.FirstRemind = [EndDate] + [DefFirstRemind], tblDateLog.SecondRemind = [EndDate] + [DefSecondRemind], tblDateLog.WarningFlag = [EndDate] + [DefWarningFlag] WHERE tblConcess.ConcesId = tblDateLog.ConcesRef AND DataDueIn = 0000-00-00
Update Syntax
I am trying to figure out a way to use mysqldump (table is too big for phpmyadmin) or another means to dump a file. Within the file, I don't want the insert syntax. What I would like to find out how to do is basically update each record (except for the field in the table that counts clicks) and then insert the records that are not in the database already. I need this in a file format because I upload the file to my server after building the 1 million record DB locally.
Index Multiple Columns
I have a table that looks like this: PlayerItems -------------------------------- | PlayerID | ItemID | ItemCount | -------------------------------- | 1 | 1 | 5 | | 1 | 3 | 1 | | 2 | 1 | 2 | -------------------------------- What index types should I use for PlayerID and ItemID so that it will throw a duplicate key error if a row is inserted that matches the playerID and the itemID. Basically im looking to run a query like this: Insert into playeritems values (1, 1, 1) on duplicate key update itemcount=itemcount+1 How should I set the indexes so it will throw a key error only whe nthe player id and item id matches.
ORDER BY Multiple Columns
I am trying to order by multiple columns, here is my example and what I want to output Code PHP ORDER BY lastName ASC, State ASC Output Quote: James Anna, Alabama Ben Bloggs, Alabama Chris Cats, Alabama Mark Aims, Delaware Hopefully you can see what I am trying to achieve, but I don't get there all it does is sort the result by lastName and ignores the states...
ORDER BY Multiple Columns
I am trying to order by multiple columns, here is my example and what I want to output Code ORDER BY lastName ASC, State ASC Output James Anna, Alabama Ben Bloggs, Alabama Chris Cats, Alabama Mark Aims, Delaware Hopefully you can see what I am trying to achieve, but I don't get there all it does is sort the result by lastName and ignores the states.
Max() With Multiple Columns W/o Groupby
I have a table with two columns ts(timestamp) and tempc(int). From this I need to pull the both of these values but where tempc is max value. Individually I can this: select max(tempc) from templog; and it works fine. However when I try this it fails: select ts, tempc from templog where tempc = (select max(tempc) from templog); I'm sure this is something inanely obvious, but I cannot seem to figure it out... Any ideas?
Search Multiple Columns
I would like to search for a keyword '%schultze%', and I would like the search to include more than one column. I was experimenting with this: SELECT * FROM `listItem` WHERE `owner` = 128 AND MATCH (`title`) AGAINST ('%schultze%'); But I would get funny errors complaining about not being able to find a FULLTEXT index. I imagine this is something that has to be built before the search happens. As the database is changing all the time, I would want this to be built once a day. Perhaps I could stick a batch file in the xinetd that would take care of that. Ideally I would like to search over 10 columns, (with the constraint that the owner equals 128) that are varchar and text, all utf8_general_ci. I suppose this would look something like: SELECT * FROM `listItem` WHERE `owner` = 128 AND MATCH (`referenceNumber`, `title`, `menus`, `added`, `format`, `ratio`, `source`, `description`, `genre`, `rating`) AGAINST ('%schultze%'); Or perhaps I'm barking up the wrong tree here and I could do a search that was like this: SELECT * FROM `listItem` WHERE `owner` = 128 AND (`referenceNumber`, `title`, `menus`, `added`, `format`, `ratio`, `source`, `description`, `genre`, `rating`) LIKE ('%schultze%'); But where mysql would know each column was OR, where '%schultze%' matches for `referenceNumber`OR `title` and so on,
Ranking For Multiple Columns
A query in my application return several columns with amounts, Now i need to add a ranking to all those columns seperatly. So the result should be something like this: ID Amount1 Ranking1 Amount2 Ranking2 ---- -------- --------- ------- -------- 135 123.34 4 23.00 3 184 160.23 1 60.89 2 845 140.22 3 100.20 1 987 155.00 2 1.20 4 The ID isnt important here. The only solution i can think of now is to create a (temp) table, populate it with the query, and then sort it for each ranking and fill the ranking one by one. Is there a way to get the ranking filled in the same pass as the amounts are calculated?
Group By Multiple Columns
I have a "users" table as follows: first_namelast_name JohnStuart JohnDell JohnStuart BillWhite If I want to know how many people of each first name there are, I do the following: select first_name, count(*) AS Number from users GROUP BY first_name; I am getting: John|3 Bill|1 But how can I get the same for both first and last name? I just don't want to count John Stuart twise. I tried: select first_name,last_name count(*) AS Number from users GROUP BY first_name,last_name; This gives me the same result as before, just adding column of first name (the same old last name grouping). I want to get: John | Stuart |2 John | Dell |1 Bill | White |1 Do I need to add multiple column index for multiple column Group By?
Select Sum(x) >0 With Multiple Columns
I am writing a script to show the average value of a question in a submitted survey form. I have 14 questions, which can have the value 1-10, if the user submitts "I don't know" it returns the value 0. When i calculate the average it includes the value 0 but still divides with all the submitted answers (see code). How can i make a select statement which only includes values > 0? Current select statement: $select = "SELECT SUM(S1), SUM(S2), SUM(S3), SUM(S4), SUM(S5), SUM(S6) , SUM(S7), SUM(S8), SUM(S9), SUM(S10), SUM(S11) , SUM(S12), SUM(S13), SUM(S14) FROM Evaluering"; I want it to do something like this : $select = "SELECT SUM(S1), SUM(S2), SUM(S3), SUM(S4), SUM(S5), SUM(S6) , SUM(S7), SUM(S8), SUM(S9), SUM(S10), SUM(S11) , SUM(S12), SUM(S13), SUM(S14) WHERE S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14 > 0 FROM Evaluering"; Any suggestions?
Selecting Min,max,avg Of Multiple Columns
I have to select "min, max, avg, sum( if( somecolumn = 123, 1, 0 ) )" from 5 to 15 columns so far, each query is for different table. Is there any other way of doing that except writing all the columns to query ? Of course that job does the script, but still, query looks miles long. Example of table: CREATE TABLE `example` ( `ID` int(255) NOT NULL auto_increment, `some_int` int(255) NOT NULL default '0', `some_int2` int(4) NOT NULL default '0', `create_time` date NOT NULL default '0000-00-00', `some_int3` decimal(65,2) default NULL, `some_int4` int(255) NOT NULL, `some_int5` int(255) NOT NULL, `a_somecolumn` decimal(65,2) default NULL, `a_somecolumn2` decimal(65,2) default NULL, `a_somecolumn3` decimal(65,2) default NULL, `a_somecolumn4` decimal(65,2) default NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; So, I have to select these "min,max,avg,sum" from all the a_somecolumn.
Multiple Records As Columns
I have a table of Sessions and a table of Speakers. Each Session could have several Speakers and each Speaker could speak on several Sessions. I have a link table containing just SessionID's and SpeakerID's. All this is working fine on a successful website. I am now trying to write a query that will return records for each Session with each of the Speakers' details for that Session. Each record could have a different number of fields according to how many Speakers were assigned to that Session - this is the bit that makes it seem difficult.
DISTINCT With Multiple Columns
I need to select unique combinations of 4 columns from one table and insert them into a new table but I can't think of any way of finding unique combinations of more than 1 column since SELECT DISTINCT only works on single columns.
Searching Across Multiple Columns
Is it possible to search for a word across multiple columns in a table? For example: Table contains columns "Year" "Make" "Model" "Color" (etc etc.....) Then, using a user entered keyword, generate a query that checks the word against all ( or a list ) of columns in that table? Something like.... SELECT * from Table where * LIKE '%keyword%'
Adding Multiple Columns
Schema on a table has changed between versions of an application I use. I'm planning on migrating the existing table (member table as is, data and schema) and then wish to add the new columns after an existing column (eg password) and am wondering do I have to add each column at a time with multiple sql statements or can I add them all in one sql? Additional columns: `invisible` set('1','0') default '0', `pmfolders` text NOT NULL, `saveogpm` char(3) NOT NULL default '', `emailonpm` char(3) NOT NULL default '', `useoldpm` char(3) NOT NULL default '', `webcam` varchar(75) default NULL,
Multiple Non-Unique Columns
I'm trying to store the call detail reports from a phone system to a database. I've successfully been able to read the CSV files it gives me into an InnoDB table using PHP. I just realized that the system does not give a single unique key in the raw data, but that two columns together will identify a unique call entry. The columns if interest are the timestamp (two people could conceivably make a call at the same time) and a call identifier (which seems to be unique over a month or so, then the system starts recycling the call identifier). With these two columns you can identify a unique call over ANY given time. I'm not sure how to use that fact to assure I'm not inserting the same data if I were to read the same CSV file twice.
Query WHERE Multiple Columns
I was wondering which is faster: creating a table with 1 column and 2 million rows OR 5 columns and about 400,000 rows the only difference is I would have to have WHERE col=1 OR col2=1 OR col3=1 OR col4=1
UNIQUE As Multiple Columns
its possible to define multiple columns as being UNIQUE - not the value of either column, but the two together. For example, you're storing people's names and addresses in a table. Two or more people could have the same lastname, and more than one person will surely have the same firstname. However, no two people can share the same lastname AND firstname. Is there a way to set this constraint?
Include Multiple Columns
I have a table with these fields: id - account - ip - data what I want to do is select only unique ip, but also include the 'data' field in the result so that I can print the unique ip along with the associated data .. is this possible?i tried 'select distinct ip,data from table' but that returns duplicate ips.
UPDATE Syntax Check
Can someone check this for syntax errors because I it won't execute without an error: CODEUPDATE pages SET NAME='index', GROUP='all', HITS='1', HTML='This is just the index page from the MySQL database! Congrats, so far so good!', HTTPS='0' WHERE NAME = 'index'
Update Syntax For Version 3.23.58
I wanted to do a simple update like this in version 3.23.58 of MySql: Update CLI, TEMP set CLI.ORN = TEMP.C WHERE CLI.ID = TEMP.CLI_ID; Turns out you can not. What is going on here and what are my alternatives?
Update Syntax For Mysql
I would like to request for your expertise. I have here an update statement which updates the table1 columns(not all columns) from the values in table2. Table1 has 20 records and Table2 has only 14 records. Like I said, I want to update the 14 records in table1 from the 14 records in table2. here is my update statement:
Bulk Update Syntax
I heard many times about bulk update, can anyone show me an example of how to do it?
UPDATE Syntax Creating New Row And Id#
I'm using the UPDATE syntax, based on the MySQL documentation: UPDATE table SET col1 = value1, col2 = value2 WHERE id = 1 * the id column is set as an auto-increment index in the MySQL setup. I want it to update/edit the row where id = 1 BUT instead, it's adding a new row with another id # with the col1 and col2 data (not quite updating the row, eh?).
UPDATE Syntax Error
I've just installed MySQL 5 on my Mac and am trying to update a couple of tables - the syntax I'm using seems to be right, but I constantly get an error. Here's what I have - feel free to point out my stupidity... SELECT ibf_members.id, ibf_pfields_content.member_id, ibf_members.mgroup, ibf_pfields_content.field_2 FROM ibf_members INNER JOIN ibf_pfields_content ON ibf_members.id = ibf_pfields_content.member_id UPDATE ibf_pfields_content SET field_2='Member' WHERE ibf_members.mgroup = 3
Correct Syntax For An Update
two databases, one has an out of date email field. I need the new table to update the email field on the old table. My query selects the rows with the wrong email address: select * FROM `oldtable` , `newtable` WHERE oldtable.memberid = newtable.memberid and oldtable.Email != newtable.email but how do I update it? update`oldtable`set oldtable.Email = newtable.email where oldtable.memberid = newtable.memberid My above query fails.
Mysql Update Syntax
I am using mysql Ver 11.18 Distrib 3.23.58, for redhat-linux-gnu (i386) I have problem with the following syntax: Update t1, t2 set t1.id = t2.id where t1.name = t2.tname OR t1.code = t2.tcode; I am trying to update the value of id in t1 using t2 attributes where the conditions fit in.
ON DUPLICATE KEY UPDATE Syntax
I have two tables with identical columns. I want to update records in tbl1 with record information from tbl2.Code: INSERT INTO tbl1 SELECT * FROM tbl2 ON DUPLICATE KEY UPDATE SET tbl1.col=tbl2.col, tbl1.col2=tbl2.col2 I seem to be missing something here...
DISTINCT Problem... I Need Multiple Columns!
$qry = "SELECT DISTINCT(`title`, `body`, `id`, `guid`) FROM news ORDER BY date DESC LIMIT 5"; That results in an error near the distinct all the way to the end. What I need, is a way to select title, body, id and guid where they are ALL unique (there are NO rows selected with the same title, body, id or guid)
|