Concat A Field In Up To 4 Rows?
A customer can have between 1 and 4 rows, is it possible to make a query that will merge field "A" of all rows and then discard all other rows leaving only 1 row left with the merged data in field "A".
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
One Field With Multiple Attached Rows, Only Show The Field Once?
I have a table called "Customers", with a field called "Customer name" and a "Customer ID". I have another table called "Projects", with a field called "Project name" and a field called "Customer ID" which references to "Customers" What i am trying to do is: Select a customer. Select the projects that are related to the customer by comparing the Customer ID field. Code:
Update One Field In All Rows
I have a mysql database which contains 24,000 rows. I added a field called "RECALL", which contain null values. What I'm trying to do is fill that field in all 24,000 rows with the value "N".
Alter One Field In A Row (300 Rows)
example changing id='1' -> id=' 5000' this must be done with over 300 ids Is there a script ot there that can do this? instead of me doing it manually.
Search Through Rows Until You Hit Field With Right Value
Basically, I'm trying to figure out how i can scroll through the rows in a mysql table until I hit a row which has a field containing a certain string. This is a ruff image of how my database looks (ignore the dots...it wouldn't let me leave white space): id | username | some_field | | some_other_field | 1..|...bill........|...............| |........................| 2..|...fred......|...a value..| |........a value.......| 3..|...ted.......|...............| |........................| 4..|...jeff.......|...............| |........a value......| 5..|...craig.....|...............| |........................| So, basically, i need to be able to start the query a Fred's 'some_field' then I need it to search on until it finds the next field with 'a value' in...in this case it would be Fred's 'some_other_field', but it could also be any other field in the table.
Count Same Field In Rows
i need to calculate the number of the same IP address that appear in the database, how can i do that? example of the database: IP Address Date and Time 127.0.0.1 5/23/2007 127.0.0.1 5/24/2007 192.168.1.2 5/25/2007 192.168.1.5 5/26/2007 127.0.0.1 5/27/2007
SELECTing Rows Where 1 Field Doesn't Repeat
Let's say I have a table something like this: id a b c 1 1 2 3 2 1 3 4 3 2 1 1 4 2 8 4 5 3 1 4 6 3 8 1 And then I want to select the rows, where "a" field doesn't repeat, so the 1st, 3rd and 5th. How do I do that?
Not Selecting Rows Where A Specified Field Is Empty
What I am trying to do in a query, is only select rows where a certain field is not empty. For example, I have a visitor logs table, with the following fields: id | date | pageVisited | referrer Now, I only want to select the rows where there is a referrer. Something like:
Concatenating Multiple Rows To One Field?
I got a slight problem with a web application, its supposed to several entries for a certain ID, and display them as one string. Example: ID | Name ------------- 1 | Jack 1 | Peter 2 | John 2 | Mark 2 | Ellis Expected Result for ID 1 should be "Jack, Peter" for example, or "John, Mark, Ellis" for 2. Least problem would be clipping off a trainling or leading ",", but the main problem is a SELECT statement to get them all in one go. Else I'd have to select every Name per ID, and concatenate them in PHP or elsewhere. Given its around 100 IDs, I'd have to do like 100 querys to get the names, *in addition* to the Querys I need before and after. I want to avoid that, but I couldnt find a simple solution that works in MySQL 4.1 and above, aswell as it mustn't involve Stored Functions or something, because I got no access to the mysqld itself, to add the funcs as modules. Code:
Select Rows Where A Field Value Exists In Another Table
I have a table with a column of email addresses I have a second table with a column of email addresses I want to select all the rows in the first table whose email value exists in the second table Can't get a query to do this without an error,
Limit Number Of Rows Or Characters Returned In A Text Field
I understand you can limit the rows of a recordset, but can you somehow tell a query to limit the rows (or characters) returned within just a text field? I have a page that returns abstracts of many articles and I want to truncate the description for each to just 200 characters. Is there a way to accomplish this with MySQL?
Concat Maybe?
Theres a way in mysql to get a comma separated list of fields in a one to many relationship - rather than multiple rows for each record in the 'one' table. But I can't remember what it is, I thought it was concat but that didn't work... I've done it before but I can't remember what it was or why.
Using CONCAT
Is it possible to make query which would select some value even column would be NULL/EMPTY ? Example: Table name John NULL Mike SELECT CONCAT_WS('something',name) FROM table; results: Johh Something Mike
WHERE With CONCAT
I have a table A with a (varchar 20) A.field and a table B with two (varchar 10) fields: B.field1 and B.field2. How can I make a SELECT with a WHERE of this type: WHERE A.field = CONCAT (B.field1 , B.field2) I get an error in CONCAT. How is the string concatenation in mySQL?
Concat
I'm trying to combine 2 fields into 1 new field using concat. This is what I using UPDATE 'idxactrs' SET 'idxactrs.desc' = concat(remarks1,remarks2) It just says "You have an error in your SQL syntax near ''idxactrs' ... Any Ideas?
Using Concat()
I'm trying to combine 2 fields into 1 new field using concat. This is what I using UPDATE 'idxactrs' SET 'idxactrs.desc' = concat(remarks1,remarks2) It just says "You have an error in your SQL syntax near ''idxactrs' ...
Use CONCAT
I'm having lots of problems using the CONCAT instruction. I'm trying to store in a variable (@f) a COUNT, but the system always crashes and I don't know why. Here you have the lines: set f=0; set @f:=f; set @stmt3:=CONCAT("select count(*) into `",@f,"` from `",@n,"` where sourceurl=`",@b,"` and link=`",@c,"`"); prepare query from @stmt3; execute query;
Concat
I'm having problem using concat select CONCAT(firstname,' ', lastname) as fullname from tbltable where fullname = 'name'; It say Unknown column 'fullname' in 'where clause'. It is my sql wrong or what?
How Does Mysql_field_len Act On CONCAT?
I am quite puzzled by this. I have two fields which if selected by themselves will return a field length of 2 using mysql_field_len. However if I select them as CONCAT(field1,' ',field2), the field length is much greater than the 5 I would expect. It looks to be about 20. Is there a way to control this length? Where is it getting the field length from? EDIT: Nevermind, this can be done using CAST(CONCAT(field1,' ',field2) AS CHAR(5))
Concat Two Tables
I have two tables, one containing payments to a supplier and one containing invoices issued by a supplier. I'd like to get a total from each table with one query. I need somehow to list all payments and all transactions together in one table result set. i.e.....
Using CONCAT In Subqueries
SELECT tblmonths.fldMonth, tblyears.fldYear, tblmonths.fldID, CONCAT(tblmonths.fldID," ", tblyears.fldYear) FROM tblmonths, tblyears where CONCAT(tblmonths.fldID," ", tblyears.fldYear) NOT EXISTS (SELECT CONCAT(fldMonth, " ", fldYear) from tblexpensesclaims) GROUP BY tblyears.fldYear, tblmonths.fldID
CONCAT And Variables
I have the following statement: ------------------ SELECT CONCAT('hxxp://www.whatever.com/all.html?t=4&p=1&u=',@c) into @c; set @stmt3:=CONCAT("INSERT INTO webs values ('",@c,"')"); prepare query from @stmt3; execute query; -------------- I think that I'm using correctly the CONCAT function but it doesn't work.
CONCAT Function (bug?)
I'm needed to insert large BLOBs into a database. With the 1MB packet limit, sending larger amounts of data would be difficult, so I had a neat idea. I would do an initial insert of an empty record and get the auto_insert ID from the response, and then loop through, appending data to the record. My table is simple. One unsigned int auto_increment field (DataID), and one long blob field (BinaryData). When I loop through the data to send, I run: UPDATE BinaryTable SET BinaryData=CONCAT(BinaryData, 'My binary data here') WHERE DataID = 35 The binary data I insert I escape null characters, backslashes, single and double quotes. The data seems to insert fine. The problem is that as I increase the amount of data in the field, CONCAT seems to drop all but the last 416k of the data. Thus if I loop through adding 400k blocks at a time (Which I do) I am left with at most 800k of data in the blob field. Using 4k blocks I end up with 419k of data in the field when all is said and done.
Update Using Concat
I have a form that I call for the data from a database table. Once the table is filled with data, the viewer has the option to add data to one field in the form. I want to be able to add the new comments without losing the old comments in the db column. Field A has the existing data ($Remarks) Field B has the new comments ($NRemarks) I have tried various CONCAT statements but none of them work, and I am thinking that this may be because Field B is not a column in the DB, as it is new information being added. Is there a way to keep the data in the DB column called Remarks and add the information in Field B to it on a seperate line. I don't know if there is a command like append or edit or add to, that will add information to the existing information. I have tried the following: $sql="UPDATE 'workorder' SET Remarks CONCAT (Remarks, NRemarks)"; ?> $sql="UPDATE 'workorder' SET Remarks CONCAT ($Remarks, $NRemarks)FROM workorder WHERE Work = '$Contact'"; ?> $sql="UPDATE `workorder` SET Remarks = CONCAT(SELECT Remarks FROM workorder WHERE Work = '$Contact', '', '$NRemarks') WHERE Work = '$Contact'"; ?>
Using CONCAT For 2 Tables
Currently I'm using this SQL query to connect 2 tables but now, I need to add a 3rd table in the same manner as the "links" table in the following query. SELECT * FROM tracker LEFT JOIN links ON tracker.location = CONCAT('link[', links.linkid, ']') ORDER BY tracker.occurred DESC LIMIT 0, 15
Problem With Concat
I have the following select: SELECT distinct name, main.ACCOUNT, concat(FlatNo,' , ',FlatName,' , ',number,' , ',`St Name`,' , ',SuburbName,' , ',`Town Name`,' , ',Stand) AS Address FROM ... I need to return all the available address information that we have but the select returns only about 15 addresses in a DB of about 100000. Some of the address fields do contain null values and the SELECT CONCAT is returning null for the whole row if any field contains a null value. Is there anyway round this? I have tried IFNULL(Field,"") inside the concat but this does not seem to work either.
CONCAT Function
I'm needed to insert large BLOBs into a database. With the 1MB packet limit, sending larger amounts of data would be difficult, so I had a neat idea. I would do an initial insert of an empty record and get the auto_insert ID from the response, and then loop through, appending data to the record. My table is simple. One unsigned int auto_increment field (DataID), and one long blob field (BinaryData). When I loop through the data to send, I run: UPDATE BinaryTable SET BinaryData=CONCAT(BinaryData, 'My binary data here') WHERE DataID = 35 The binary data I insert I escape null characters, backslashes, single and double quotes. The data seems to insert fine. The problem is that as I increase the amount of data in the field, CONCAT seems to drop all but the last 416k of the data. Thus if I loop through adding 400k blocks at a time (Which I do) I am left with at most 800k of data in the blob field. Using 4k blocks I end up with 419k of data in the field when all is said and done. Please let me know if/when this will be fixed, and if there is a work around that might be used, r a better way to insert BLOB data is known.
CONCAT All Columns
I want to produce a query that does something like this: SELECT MD5(CONCAT(*)) FROM table WHERE 1 * is all the columns. I don't want to have to type in every column name, but have MySQL do it.
Problems With Concat
I'm having problems with Concat. I have this piece of code: set @m:=a; SET @stmt1:=CONCAT("INSERT INTO ",@m," VALUES (b,c)"); PREPARE query from @stmt1; execute query; b and c are cursors and when it tries to execute the query and I get the following error: "Unknown column 'b' in field list" It seems that is not doing correctly the CONCAT?
Concat For Numbers
I am interested in performing a concat for numbers with a space e.g. select concat (num1, ' ', num2) from tablex as numconc such that if num1 is 123 and num2 is 456 the result would be '123 456' I believe concat should work for a string rather than number format, however having created the fields num1 and num2 in string format it still does not work. Any advice on why this isn't working, or an alternative method to achieve the result would be most welcome.
Help With Subquery / Group Concat
I've attached some data from which I want to extract individual itinerary ids and show the ships which go to those destinations. The problem is that the destination ids are stored as comma separated values in a single field and there are rows which duplicate the same associations between the ship and destination ids. I can do: SELECT ship_id, GROUP_CONCAT(DISTINCT destination_ids) FROM itineries GROUP BY ship_id; and get a list of destination ids for each ship but what I actually want is a list of ships for each destination Id. Can somebody give me some pointers on how to achieve this? I think it might be possible with a subquery but am not sure how to go about this. MYSQL version is 4.1.20.
SELECT CONCAT() Subquery
SELECT * FROM (SELECT CONCAT(comments.category,'s') FROM comments WHERE comments.author_user_id = '1') The subquery alone yields "post" (`comments.category` is an ENUM() field); and I want to select all the rows from the "posts" database table. Ideally, the query would be processed like: SELECT * FROM posts How do I perform a string concatenation during a SELECT query?
SELECT Subquery CONCAT
SELECT * FROM (SELECT CONCAT(comments.category,'s') FROM comments WHERE comments.author_user_id = '1') The subquery alone yields "post" (`comments.category` is an ENUM() field); and I want to select all the rows from the "posts" database table. Ideally, the query would be processed like: SELECT * FROM posts How do I perform a string concatenation during a SELECT query with MySQL?
CONCAT () Returns BLOB
MySQL ver. 3.23.49 SELECT tblHrsClass.classid , CONCAT( tblHrsClass.classTtl ,' ', tblHrsClass.classDate ) class_ttl FROM tblHrsStudent LEFT JOIN tblHrsClass ON tblHrsStudent . classid =tblHrsClass.classid GROUP BY tblHrsClass . classid HAVING COUNT(tblHrsStudent . classid )<19 The query above is broke. I'm using it to build a list box. I can run the query without the CONCAT function and pulls the expected data. When I add CONCAT( tblHrsClass.classTtl ,' ', tblHrsClass.classDate ) class_ttl, class_ttl is returned as a BLOB of a certain size.
Need To Concat Column And DATE_FORMAT
I'd like to combine the title and starttime so I can distinguish amongst several requests with the same title. ie: ID=7116 name=Testing11-26-2007 Here's my query: select ID, title+DATE_FORMAT(starttime,"%m-%d-%Y") as name from requests where ID=7116 Which gives me: ID=7116 name=11 What do I need to do to get the result of DATE_FORMAT into a form that will concat with the text from another column?
Concat 2nd Table Results Into First?
Given three tables used to track multiple email addresses and phone numbers for a person: Table 1: id, name, address Table 2: table1_id, email Table 3: table1_id, phone How can I do a select to end up with all emails and phones concated together into a single row per individual: id, name, address, "email,email,email", "phone,phone" The solution needs to work with MySQL 3.23 (or possible MySQL 4.0). 4.1 is NOT an option, so group_concat is out.
CONCAT Length Limitation
I have encountered a problem while using the CONCAT command to update a column with a size over 1mb, the existing information is lost. I can't seem to find a suitable alternative to update a field in a row with several appends. the data length in total will be exceeding over 16mb at times.
GROUP CONCAT Issue
Iam using Mysql Version 5.0. the query, SELECT GROUP_CONCAT(field_name)FROM TABLE1; This returns BLOG as result set in the editor in my Toad. What is the issue, i have just 300 records in my table. Why this happens, please help
Nesting A 'concat' Within A 'replace'
I have the_table: col_1 , col_2 ------------------------- aaa , aaa_do aaa_dat the query that I am using:"update the_table set col_2=replace(col_2,col_1,concat('hoorah_' , col_1) ) " I want col_1 , col_2 ------------------------- aaa , hoorah_aaa_do hoorah_aaa_dat however the query does not successfully stick the 'hoorah_' in front of the aaa_dat; instead I get this: col_1 , col_2 ------------------------- aaa , hoorah_aaa_do aaa_dat
Problem W/concat To Date
I am trying to run a report that displays data that falls between a date range. The dates are entered in mm/dd/yyyy format. I convert the date using ColdFusion code for MySQL to use: cfset Start1c = DateFormat(#Start1#, "yyyy/mm/dd") cfset End1c = DateFormat(#End1#, "yyyy/mm/dd") The query that uses this variable will run as long as I, 1. use slashes in the date variable above 2. query for data that falls in the same year Here is the part of my query that has a problem w/the formatting of this date: date_format(date_sub(concat_ws('-',dataYear,dataMonth,'02'), interval 1 day), '%Y-%m-%d') BETWEEN '#Start1c#' AND '#End1c#' AND InputMethod = 1 dataYear and dataMonth are integer fields combined to create a date.
INSERT With Concat Auto_increment
I have a table that stores online orders. Each row in the table uses auto_increment to create a unique id for each order, in a field "id". Each order (row in the table) also has a serial_number field that has a string representing the product and a unique number representing the order. I would like to append the id field value for the newly created order to the product string, to create the serial number. Can this be done within a single SQL statement or do I need to insert the order, find out the id, then update the order and appending the id on the serial number string. Is it possible to append the id of the newly inserted row to another field in the row in a insert statement? I tried INSERT INTO orders SET serial_number = CONCAT('product text',id); but MySQL did not like the id column in the concat function. Do I need to use LAST_INSERT_ID to find the id?
Updating Rows In Table B Based On Related Field In Table A
Ver 4.1.8-standard for apple-darwin7.6.0 on powerpc (Official MySQL-standard binary) I am trying to do some data migration based. I have several tables that contain our legacy pkey field and I want to update the tables with new ID's. I need to do this several times and have tried it several ways to no avail. Table A --------- companyID int(10) pKey legacyID int(10) old legacy pkey Table B --------- bAID int(10) pkey companyID int(10) legacyID int(10) Table A has values for both companyID (unique key) and legacyID. Table B has values for bAID (unique key) and legacyID but companyID is empty. I need to update tableB.companyID with tableA.companyID based on tableb.cSerialID to tablea.cSerialID relationship. I need a query that will update ALL rows.
SELECT Where String Matches CONCAT Value?
I'm setting up a database where an order number is concat() of the company ID + order ID + timestamp year (2 digit). How would I find a string match to the order number without storing it explicitly in the database? Here's a simplified version of the 2 tables involved... CREATE TABLE `companies` ( `id` int(10) unsigned NOT NULL auto_increment, `prefix` varchar(3) NOT NULL, `description` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; CREATE TABLE `orders` ( `id` int(6) unsigned zerofill NOT NULL auto_increment, `company_id` int(10) unsigned NOT NULL, `time_stamp` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; ...and here's what I was trying to find an order number match: SELECT orders.id FROM orders LEFT JOIN companies ON companies.id=orders.company_id GROUP BY orders.id HAVING ( CONCAT(companies.prefix, orders.id, '-', DATE_FORMAT(orders.time_stamp, '%y')) LIKE '%whatever%' ) But I'm getting an error "#1054 - Unknown column 'companies.prefix' in 'having clause'". If I remember right, it's because I'm not selecting the fields from the having clause, and they're not in the group by statement. So, how would a fellow do what I'm trying to do? Should I just accept the redundancy and insert the full order number into the database?
Help With UPDATE Using CONCAT On Longtext Fields
I have two tables with longtext fields that I'd like to concatenate and update in one of the tables. Not sure if you can use concat on a longtext field. Here's what I tried: UPDATE `node_revisions`, `weblink` SET `node_revisions`.`body`=concat(`node_revisions`.`body`,"<br /><a href="",`weblink`.`weblink`,"">Visit this site</a>") WHERE `node_revisions`.`nid` = `weblink`.`nid`; This is the scenario. I have these 2 tables: node_revisions table ----------------------------- | id | nid | body (longtext) | ----------------------------- | 1 | 23 | this is some text | ----------------------------- weblink ----------------------------- | id | nid | weblink (longtext) | ----------------------------- | 5 | 23 | http://somesite.com | ----------------------------- I'm trying to use UPDATE to concatenate the node_revision.body and weblink.weblink fields, where they share foreign key nid. So the resulting node_revisions would look like: node_revisions table ----------------------------- | id | nid | body (longtext) | ----------------------------- | 1 | 23 | this is some text<br /><a href="http://somesite.com">Visit this site</a> | ----------------------------- When I run the UPDATE statement above, I get the following feedback, but nothing has in fact changed: Query OK, 813 rows affected (0.15 sec) Rows matched: 813 Changed: 813 Warnings: 0
Concat Columns Based On Certain Criteria Using Only SQL?
I have a big table (15 million records). Each row has a parsed address (number, prefix, street, type, suffix) and I need to take these separate pieces and concatenate them. However, often times a few of those pieces will be blank, so I want to prevent any unnecessary spaces. I'm using MySQL 4.1. I found some documentation for using if statements for MySQL 5.0, tho I dont know if any of it works in 4.1. The basic psuedo code of what I want to do is this:
Create & Store A Concat String
I have two tables: keywords(itemID, WordID) and words(WordID,Word) I would like to create a single string of the words associated with a single ItemID by concatenating words and store them into a new table wordstring(itemID, wordstring).
Illegal Mix Of Collations When Using The Concat Function
SELECT concat('hello world ', cui) FROM `umls_cuis` I am using MySQL 4.1.3-beta. I get the following error when trying to execute the above SQL: ERROR 1267: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (utf8_general_ci,IMPLICIT) for operation 'concat' What can I do about it?
|