MYSQL - two tables in different databases - mysql

I need to check phone number to see if they match but the issue is, that one table is in database A and another is in database B.
I am wondering is there away to do a search like this:
update `chk_dup`, new set chk_dup.dup='Y' WHERE chk_dup.phone = new.phone;
But I guess I would need to do something like this:
update `A.chk_dup`, B.new set A.chk_dup.dup='Y' WHERE A.chk_dup.phone = B.new.phone;
I any one knows how to search two tables in completely different databases that would help.

I think in your second one you had a syntax error, try this one:
UPDATE `A`.`chk_dup`, `B`.`new`
SET `A`.`chk_dup`.`dup`='Y'
WHERE `A`.`chk_dup`.`phone` = `B`.`new`.`phone`;

Related

Updating/changing a specific portion of a string in mysql?

I have tried a couple different approaches to doing this, and all seem to return an error. So in this exact situation, I'm trying to replace something in garrysmod with another. In this case, it's a playermodel. And I'm using the mysql pointshop. I want to replace specifically in the items row only the word "ironman" with "vector". Here are the different ones I have tried:
UPDATE `pointshop_data` SET `items` = REPLACE(`items`, 'ironman', 'vector')
and
UPDATE pointshop_data SET items = REPLACE(items, 'ironman', 'vector') WHERE items LIKE '%ironman%';
Both of which came from here: MySql - Way to update portion of a string?
Any different approaches I've tried I get the same syntax error: http://gyazo.com/03a6774b2d78956a8c5b41c588e9c568
I feel like I'm missing the smallest step here, but I did exactly as the answers stated in the other question.
try following query:
UPDATE 'pointshop_data' SET items = REPLACE(items, 'ironman', 'vector') WHERE items LIKE '%ironman%';

How to fetch databases by name?

I have 4 databases:
auth ; auth_backup ; auth1 ; auth1_backup ;
I want to fetch only the ones with the "_backup" extension.Is there a way?
Just with php and sql.And if its possible with mysql not mysqli(i know its deprecate but i have to use it
Until now i tried:
$sql4="SHOW DATABASES LIKE '%backup%'";
$query4=mysql_query($sql4,$connect);
$row1=mysql_fetch_assoc($query4)
but in this way,it doesnt work what i am trying to do.So i need something somehow to fetch only the specific dbs.Also if its possible to drop some specific dbs,this will do it too..
Try the following statement:
SHOW DATABASES WHERE `Database` LIKE '%_backup'
This will fetch the databases for you with the name _backup in it.

Transfering data between one data base to another in SQL

I am trying to transfer a couple of columns from an old database to a live database.. The issue I have is that I need the columns to match up with a column on the live database. For instance let me use an example: My live database has a table like this
TABLE NAME is ITEMS Then inside the table there would be a columns name ItemLookUp and ExtensionDescription.
So the live table would look something like this:
**ItemLookUp** **ExtensionDesctiption**
AAA-06-201 'Blank'
BBB-08-201 'Blank'
CCC-99-201 'Blank'
The old database would look like this:
**ItemLookUp** **ExtensionDescription**
AAA-06-201 Toy part
BBB-08-201 Mechanic Part
CCC-99-201 2x1 Screw
So what I am trying to do is make the live database have the information of the old database, but the ExtensionDescription needs to match up with the ItemLookup meaning for example if the ItemLookUp is AAA-06-201 it must have an ExtensionDescription of Toy part... Any help would be greatly appreciated.
Try on this. I thik this will help you.
update tbnew
set tbnew.ExtensionDesctiption = tbold.ExtensionDesctiption
from tbold
where
tbnew.ItemLookUp = tbold.ItemLookUp
UPDATE dbnew.items a JOIN dbold.items b
ON a.ItemLookUp=b.ItemLookUp
SET a.ExtensionDescription=b.ExtensionDescription
Assuming same server.
Figure it out.. Thanks for all your help
update Item
set ExtendedDescription = X.ExtendedDescription
from Item I
INNER JOIN /old db name/raxx.dbo.Item X on I.ItemLookupCode = X.ItemLookupCode
WHERE I.ItemLookupCode = X.ItemLookupCode AND I.ExtendedDescription like ''

phpmyadmin SQL query multiple tables

I have two tables.
(1) compressors
(2) crankcase_heaters
I'm trying to create a SQL query to do:
Select the compressor.VOLTAGE and compressor.WATT of each compressor.PART_NUMBER
Find the crankcase_heater.PARTNO that has the same voltage and watts.
Add that value into a new field on the compressor table called "CRANKHTR"
Essentially this query will reproduce my compressors table but will have another 'column' called "CRANKHTR".
I'm completely lost on where to even start with this. I tried using the phpmyadmin SQL Query builder but i have no idea where to begin.
Without seeing the exact data structure, it sounds like you need a simple INNER JOIN:
SELECT
`cp`.`VOLTAGE`,
`cp`.`WATT`,
`ch`.`PARTNO` as CRANKHTR
FROM
`compressor` cp
INNER JOIN `crankcase_heaters` ch ON ch.VOLTAGE = cp.VOLTAGE AND ch.WATT = cp.WATT

How do I remove an email domain value and add a new one in a column - mysql

So I have a bunch of users in a column that get refreshed as:
Bill#test.comXYZ
Tom#test.comXYZ
John#test.comXYZ
We refresh the database each week and I need to update these appropriate emails to:
Bill#domain.com
Tom#domain.com
John#domain.com
I figured I can use concat to do the latter, but I am stuck on the former issue. Is there a way to split the values (like split Bill#test.comXYZ into Bill - #test.comXYZ and then remove the #TEXT values?).
Anyways, any help will be much appreciated.
You can use the mySQL replace function, i.e.
UPDATE mytable
set myfield = replace (myfield, '#test.comXYZ', 'domain.com')
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace