Find the same and replace it - oracle

There are 2 tables:
Now I want to query the title of the author table for the same value as the barcode field in the holding table. Then? Add the value of Auth in author to callNo in holding .
This is what I wrote:
update holding h set
h.CALLNO = (select a.author
from AUTHOR a
where a.TITLE = h.BARCODE)
This statement is wrong, it transformed my column into null.

Related

Get value from SQL what was relation from other list. (Oracle APEX 21.11)

I want to display a value to the text field; it is from a SQL query. And that SQL's WHERE keyword is from the list item.
Searching by ID in the selected row will return a single item.
SELECT SHOP_NAME, ID FROM M_SHOP WHERE ID = '(selected ID)';
Just use page item's name preceded by colon (:) sign. For example, if that ID represents department ID and page number is 1, that could be
SELECT SHOP_NAME, ID FROM M_SHOP WHERE ID = :P1_DEPARTMENT_ID

consider subquery of the same table in materialized view creation

Good afternoon,
how can I edit my select to avoid subquery error message inside materialized view.
ORA-22818 subquery expressions not allowed here
create materialized view vista1
refresh complete on demand
as
select f1.codigo,f1.Car,f1.codCard,f1.descripcion,f1.caracteristicas,
f1.razonsocial
f1.codigoAbs,
f1.codigoCarAbs,
(select ff.Car
from persona ff
where ff.codigo=f1.codigoabs
and ff.codCard=f1.codigoCarAbs
and rownum=1) as "absorbed reference"
from persona f1
The logic of the table and columns is as follows:
the "persona" table has columns that identify other people who were absorbed or are under guardianship,these columns are:
-codeABS y codigoCarABS
I cannot edit the structure of the tables or create others.
description:
1-the "codigo" field is the primary key of the "persona" table.
2-the "codCard" field is a unique code of the "persona" table.
3-the "codeABS" field, indicates the code of the "persona" who was absorbed, it belongs to a code from the same "persona" table.
4-the "codigoCarABS" field, indicates the CAR code of the "persona" who was absorbed, it belongs to a code from the same "persona" table.
How about a join?
SELECT f1.codigo,
f1.car,
f1.codcard,
f1.descripcion,
f1.caracteristicas,
f1.razonsocial,
f1.codigoabs,
f1.codigocarabs,
f2.car AS absorbed_reference
FROM persona f1
JOIN persona f2 ON f1.codigo = f2.codigoabs AND f1.codigocarabs = f2.codcard;
ROWNUM = 1 you used implies that there might be 2 or more rows; I believe that "my" query then misses the where clause which would make sure that only one value from f2 is fetched. Is there some timestamp column, ordinal number, ... that helps with that? If not and you don't really care which value to return, you could apply e.g. MIN function to f2.car and put the rest of selected columns into the group by clause:
SELECT f1.codigo,
f1.car,
f1.codcard,
f1.descripcion,
f1.caracteristicas,
f1.razonsocial,
f1.codigoabs,
f1.codigocarabs,
MIN(f2.car)AS absorbed_reference
FROM persona f1
JOIN persona f2 ON f1.codigo = f2.codigoabs
AND f1.codigocarabs = f2.codcard
GROUP BY f1.codigo,
f1.car,
f1.codcard,
f1.descripcion,
f1.caracteristicas,
f1.razonsocial,
f1.codigoabs,
f1.codigocarabs;

DELETE SQL: how delete only one value at a time

i have this sql string
"DELETE FROM project.cart WHERE isbn = ?";
If the table there are many isbn same, I can delete a single isbn every time I click on jbutton?
PS: isbn = ? -> takes its value from a txfield and it all works, but if there are equal isbn delete them all of course.
thanks to all.
Oracle inserts a hidden column called ROWNUM
DELETE FROM project.cart WHERE isbn = ? and ROWNUM=1;

Save many to many relationship in datamapper ORM - Codeigniter

I am a beginner. Here I would to ask all of you that how can I save many to many relationship in to the three tables(table A , table A-b , table B)? Now I am trying to save a new record with new ID into table A, and I have some IDs of table B that I want to save them to the middle table A-B depend on ID of table A. If anyone have experiences with this, please kindly share.
Example:
$a = new modelA();
$a->name = ‘new name’;
$a->des = ‘something to say’;
$b = new modelB();
$IDs = new array(1,2,3); //IDs of records in table B
$a->save(array($IDs=>$b));
Passing ID's is not supported, Datamapper needs objects to be able to relate.
If you have an array of ID's, you can fetch the objects using an where_in() query, and then save the relation using
$a->save($b->all);
I have some values which get from post form like:
'new name'
'new description'
array('val1','val2','val3')
in my controller I want to save a new record to table A with:
- 'new name'
- 'new description'
and array('val1','val2','val2') I got IDs of them from table B which has many to many with table A(a new record going to save).
So when I save into table A, the IDs of table B also save to middle table A-B with new ID of table A I just save. How to save?

Linq2Entity Getting Values from reference Table

i have 3 tables
Table: A
- aID
- Text
Table: B
- bID
- Text
Table: A_B (reference table which holds both of the primary keys as foreign keys)
- aID
- bID
The Entity Framework knows that Table A_B is just a reference table and does not create it in the DBModel but keeps the references in Table A and B.
My question is how do i get the data which is in the reference table without actually having this table? When i try to access the values of Table B using the reference which is in Table A i cant get the values of the Table B Colums.
ObjectQuery<A> aTable = dbConnection.A;
var result = from data in aTable
where data.aID = '12'
select data.B; //B is the reference to table B out of table A
What i need is something like:
ObjectQuery<A> aTable = dbConnection.A;
var result = from data in aTable
where data.aID = '12'
select data.B.bID;
How do i get data out of Table B using the reference between Table A and Table B?
Using: VS 2010 Prof, .Net 4, Linq2Entity
As Gary Said, you either use First (if you want one B for each A), FirstOrDefault (if you want nulls where there is no B for A) or SelectMany (if you want all Bs for each A)
The latter can be written like this:
var result = from data in dbConnection.A
from b in data.B
select b.Id;

Resources