I have a MySQL table with 4 millions of records having a field like "hello#xyz.com22-03-2015". Concatenated date is not fixed for all 4 million records. I am wondering how can I remove the numbers or any string after #xyz using mysql. One possible solution must be somehow with Regular expression and I know that Mysql does not allow replace using regex, so I am wondering how this particular task can be completed. I want to remove everything after #xyz.com
Many thanks
Related
I have imported a few thousand records in my existing CRM database from CSV and apparently all leading zeroes in the phone numbers column have disappeared. In searching for an answer all other questions I could find were about fixed length of the string. but my phone numbers vary in length. The ones that need their leading zeroes back are the ones starting with different than zero number. The old records (prior to my CSV import) are fine and I do not need another zero to go in front of them.
Please bare in mind I am not a programmer and this is all very difficult to me - even to explain.
I've tried to export the database table via phpmyadmin in CSV and sort the problem out in LibreOffice and then put it back (import) ...but there are records NULL that are not in quotes "" when exported and when I save the file in LibreOffice all fields are in quotes including the NULL ones. So I guess this will not work. It is a production environment. The table in question is the "contacts" table for a SugarCRM CE database. The field is varchar(100). So to summarize my question is: is there a function that I can put in phpmyadmin or in the terminal (i have root access), that will identify the records in this particular table (contacts), that start with number different than zero and ad one zero in front?
I know that I am expected to show a code that I've tried and to give some feedback what the result is, but I just can't. Sorry. Any help will be highly appreciated.
UPDATE table1 SET phone = CONCAT("0", phone) WHERE LEFT(phone, 1) <> "0";
You can first run SELECT with the same condition to see if it correctly return the rows that have phone numbers that lost their leading zeros
is there a way to delete from a table an email address that has a certain amount of numbers in a string. For example, g1az11#hotmail.com would be fine as it has 3 numbers in there but g1az111#hotmail.com would be removed since there are 4numbers in the string.
I need this to be done in a pure MySql query I am not able to run through these through PHP first.
I have job in Talend that is designed to bring together some data from different databases: one is a MySQL database and the other a MSSQL database.
What I want to do is match a selection of loan numbers from the MySQL database (about 82,000 loan numbers) to the corresponding information we have housed in the MSSQL database.
However, the tables in MSSQL to which I am joining the data from MySQL are much larger (~ 2 million rows), are quite wide, and thus cost much more time to query. Ideally I could perform an inner join between the two tables based on the loan number, but since they are in different databases this is not possible. The inner join that is performed inside a tMap occurs after the Lookup input has already returned its data set, which is quite large (especially since this particular MSSQL query will execute a user-defined function for each loan number).
Is there any way to create a global variable out of the output from the MySQL query (namely, the loan numbers selected by the MySQL query) and use that global variable as an IN clause in the MSSQL query?
This should be possible. I'm not working in MySQL but I have something roughly equivalent here that I think you should be able to adapt to your needs.
I've never actually answered a Stackoverflow question and while I was typing this the page started telling me I need at least 10 reputation to post more than 2 pictures/links here and I think I need 4 pics, so I'm just going to write it out in words here and post the whole thing complete with illustrations on my blog in case you need more info (quite likely, I should think!)
As you can see, I've got some data coming out of the table and getting filtered by tFilterRow_1 to only show the rows I'm interested in.
The next step is to limit it to just the field I want to use in the variable. I've used tMap_3 rather than a tFilterColumns because the field I'm using is a string and I wanted to be able to concatenate single quotes around it but if you're using an integer you might not need to do that. And of course if you have a lot of repetition you might also want to get a tUniqueRows in there as well to save a lot of unnecessary repetition
The next step is the one that does the magic. I've got a list like this:
'A1'
'A2'
'B1'
'B2'
etc, and I want to turn it into 'A1','A2','B1','B2' so I can slot it into my where clause. For this, I've used tAggregateRow_1, selecting "list" as the aggregate function to use.
Next up, we want to take this list and put it into a context variable (I've already created the context variable in the metadata - you know how to do that, right?). Use another tMap component, feeding into a tContextLoad widget. tContextLoad always has two columns in its schema, so map the output of the tAggregateRows to the "value" column and enter the name of the variable in the "key". In this example, my context variable is called MyList
Now your list is loaded as a text string and stored in the context variable ready for retrieval. So open up a new input and embed the variable in the sql code like this
"SELECT distinct MY_COLUMN
from MY_SECOND_TABLE where the_selected_row in ("+
context.MyList+")"
It should be as easy as that, and when I whipped it up it worked first time, but let me know if you have any trouble and I'll see what I can do.
I have an ODBC linked table from JDE/AS400 that I'm bringing into MS Access 2010. The table has four fields with data types of decimal that I need to convert to double data types once I've written them to a temp table. Is there not a way to have four alter table/column statements in one query?
In case anyone is wondering, the data stored in these fields is price and cost, but they are stored in the ODBC table as decimal values of 15 with 0 trailing decimals and I have to divide two by 10,000 and one by 100,000 to get the decimal points in the right position to represent the true price/cost For example, 3558767 in the price field is actually a price of 355.8767 or 355.88 rounded). When I bring the same data into Access and divide by 10000, I get 355.00. I need the correct cents value. The only way I've been able to do this in the past is to write an alter table/alter column query to change the data type to double before performing the division.
Since I have four of these fields, I'd like to alter or modify all four at once. Any ideas?
Any help is appreciated.
There isn't a way in Access (or ANSI-compliant SQL, as far as I'm aware) to alter multiple columns at the same time; you would have to either:
run four separate alter scripts, or ...
create a new temporary table, move all the data into the temporary table, drop the main table, then rename the temporary
It's really a wash in this case, since you'll be running four scripts either way.
As mentioned, Access SQL won't allow you to alter more than one column with a single SQL statement. However, there is something confusing about the background information in your question.
SELECT decimal_field/10^4 AS my_quotient
FROM tblFoo;
decimal_field is Decimal type with precision = 15 and scale = 0.
When I store 3558767 to decimal_field and run that query, Access 2007 gives me 355.8767 as my_quotient. And that's the result I understood you want but aren't getting.
If you can sort that out perhaps you don't need to alter any column.
Let's say that we have one table with a field called sales_total and another table with a bunch of sales entries. Let's also, for a moment, imagine that it is impractical to count the entries every time we want to see the total number of sales.
Is it possible to have MySQL automatically update the sales_total field every time the number of sales entries changes?
I know that you can do this by running another query via C#, PHP or whatever - I'm just curious whether MySQL (or some other database system) can do this within itself?
P.S. This is of course a pretty banal example - the ideal solution should be able to handle more complex operations (storing several rows as a string in a field, etc).
use mysql trigger...
trigger on update from the first table should have some queries to update the second table.