How to modify an unique row from duplicated rows - pervasive-sql

I am working with an existing Pervasive v10 database. In a table I have duplicated rows without an unique descriptor (no primary key).
I would like to modify only the first row with the SQL command update. The table History have 3 columns only :
Document : a VARCHAR
Link : a number
Description : a VARCHAR
The result of :
select * from History where Document = 'IN10001' and Link = 3
is giving 2 identical rows :
'IN10001'; 3; 'Invoice 2'
'IN10001'; 3; 'Invoice 2'
Could someone help me to change the field: Link for only one row?

Related

SQL Join Problem Table two has more as one Record for ID

I have a SQL query problem.
i have two tables.
Table One UINT ID and same Fields
Table Two have Records with ID from the first Table. but more than one record for the ID.
Table Two:
ID=1 StringField1= "Hello" Stringfield2="World"
ID=1 StringField1= "Auto" Stringfield2="Street"
Is there a way to construct a query in such a way that I get a record of the form
1,Hello,World,Auto,Street,....etc.
Lot of Thanks.
Winfried
Have you a solution for this Problem?
Hello.
In Table 1 as the main Table is the field C_URI. This Field is the Key for the Table 2 , Field FK_Workitem. In Table 1 is one Record for the Key.
In Table 2 are the Costumer Fields with teh Fieldname and Feild value. in our Example:
Field 1 -> Name variationType value -> mandfeature
Field2 -> Name swe1_coverage value -> started
I now want to make a query in which I only have one record
C_URI, variationType value, swi_coverage value.
What must i do?
Select Statement
Output

Information Schema HIVE

I am working on HIVE and using DBVisualizer. I want to get all the table which has a particular column in a database.
For example : If there is a database which has a 2 tables:
Table_1 :
Columns:
A
B
ABC_ID
ABC_DT
C
Table_2 :
Columns :
C
D
ABC_X
ABC_Y
I want to get a list of tables and corresponding columns which contains a substring "BC_" and also if I can add a filter for database that would be helpful.
I know how to do this in SQL server, but on hive I am not able to figure this out.

Using REPLACE AND LIKE

I am currently trying to update a column in a temporary table using Oracle 11g SQL syntax. In this column there is an Unique ID that is 12 digits long. However I need to join this table with this column holding the Unique ID but the syntax for the Unique ID of this table is slightly different than the syntax for the table that it will be joined (with Unique ID serving as the PK = FK). This may be tough to follow so I will provide what I am doing below.
UniqueID Column from TABLE xyz Syntax
AB10783421111111
UniqueID Column from TABLE zxo Syntax
383421111111
You see how the numbers are identical except for the AB107 and first '3' in the zxo table? I would like to know why both these queries are not running
UPDATE temp37 SET UNIQUE_ID = REPLACE(UNIQUE_ID, (LIKE 'AB107%'), (LIKE '3%'));
UPDATE temp37
SET UNIQUE_ID = '3%'
WHERE UNIQUE_ID = 'AB107%';
Essentially I would like to replace every case of an id with AB10755555555555 to 355555555555. Thank you for any help.
You can do:
UPDATE temp37 SET UNIQUE_ID = REPLACE(UNIQUE_ID, 'AB107', '3');
OR
UPDATE temp37 SET UNIQUE_ID = CONCAT('3', substr(UNIQUE_ID, 6)) WHERE UNIQUE_ID LIKE 'AB107%';

SQL insert row with one change

I have this table:
Table1:
id text
1 lala
And i want take first row and copy it, but the id 1 change to 2.
Can you help me with this problem?
A SQL table has no concept of "first" row. You can however select a row based on its characteristics. So, the following would work:
insert into Table1(id, text)
select 2, text
from Table1
where id = 1;
As another note, when creating the table, you can have the id column be auto-incremented. The syntax varies from database to database. If id were auto-incremented, then you could just do:
insert into Table1(text)
select text
from Table1
where id = 1;
And you would be confident that the new row would have a unique id.
Kate - Gordon's answer is technically correct. However, I would like to know more about why you want to do this.
If you're intent is to have the field increment with the insertion of each new row, manually setting the id column value isn't a great idea - it becomes very easy for there to be a conflict with two rows attempting to use the same id at the same time.
I would recommend using an IDENTITY field for this (MS SQL Server -- use an AUTO_INCREMENT field in MySQL). You could then do the insert as follows:
INSERT INTO Table1 (text)
SELECT text
FROM Table1
WHERE id = 1
SQL Server would automatically assign a new, unique value to the id field.

Selecting and inserting (copying rows with partially unique values)

I would like to copy rows in my table to the same table but change the unique values (so i dont get duplicates of the unique). Using MS SQL Server 2008
Table example
ID NAME POS TYPE DATA
XXXXXXXXXXXXXXX_TTTT Something Hefty 0 01DAT 2008-09-29
XXXXXXXXXXXXXXX_WWWW Something Hefty 2 01RAT Random txt
ZZZZZZZZZZZZZZZ_YYYY Something Else 1 01DAF Random value
None of the columns have any keys and all columns are of Varchar data type.
Now what i want to do is to select theese rows and insert them (like a copy paste ish thing) but i want to keep the _YYYY, _TTTT and _WWWW (they are replacements and are unique for each X or Z ID- which means that _TTTT can be the same as _YYYY since X and Z are diffrent) in the ID column but make new XXXXXXXXXXXXXXX and ZZZZZZZZZZZZZZZ part of the ID. Also i want to change the NAME since it has to be unique with the XXXXXXXXXXXXX ID or ZZZZZZZZZZZZZZZ ID. (The X ID has one name and the Z ID has another.)
Here is the statement i try to use (its incomplete since i cant figure it completly out)
insert into Table_name(ID,NAME,POS,TYPE,DATA)
select 'XXXXXXXXXXXXXXX'+substring(ID,15,5), NAME+'(Copy)',POS,TYPE,DATA
from Table_name where NAME='Old name' or NAME='Old name 2'
The 'Old name' and 'Old name 2' part is to be able to pick which NAME that i want to copy (most of times more than 5).
So the help i need with is to make new unique XXXXXXXXXXXXXXX and ZZZZZZZZZZZZZZZ ID's for each name.
I'm not sure if I understood correctly, but what you might need is UPDATE:
UPDATE table_name
SET ID = REPLACE(ID, '_', '')
, NAME = NAME + ' ' + REPLACE(ID, '_', '')
If you can change that table design, you should really do that, for instance create INT type column for ID, add primary key constraint etc.