Update a query using two tables
CREATE TABLE T1
FIELD1 VARCHAR2(10),
VALUE1 INTEGER,
FIELD2 VARCHAR2(10),
VALUE2 INTEGER
INSERT INTO T1 VALUES('OLD',100,'NEW',1000);
INSERT INTO T1 VALUES('OLD',200,'NEW',2000);
INSERT INTO T1 VALUES('OLD',300,'NEW',3000);
CREATE TABLE T2
FIELD VARCHAR2(10),
VALUE INTEGER,
NAM VARCHAR2(10)
INSERT INTO T2 VALUES('OLD',100,'ABC');
INSERT INTO T2 VALUES('OLD',200','ABC');
INSERT INTO T2 VALUES('OLD',600,'ABC');
INSERT INTO T2 VALUES('OLD',300,'XYZ');
Currently there are old values in the table T2.But the current requirement is the corresponding new values present in table T1 should get reflected.One more condition is the NAM='ABC'
I am trying to write in this way.It's getting target updated by multiple source rows.Please help in thi sregard.
UPDATE T2 A
SET A.FIELD=B.FIELD2,A.VALUE=B.VALUE2
FROM T1 B INNER JOIN T2 A
ON T2.VALUE=T1.VALUE1
AND T2.NAM='ABC'
Regards
KVB
You need something more like...
UPDATE T2 A
SET (A.FIELD, A.VALUE)=(SELECT B.FIELD2,B.VALUE2
FROM T1 B
WHERE A.VALUE=B.VALUE1)
WHERE T2.NAM='ABC'(untested)
Similar Messages
-
Friends,
I need to select some fields from two different tables which doesnot contain any field in common.How to Get this using a select query..
But there is a field X in table 1 which is equalient to eight char of another field y in table 2.I tried using offset but it is giving error.
Thanks in Advance
Regards
YaminiHello,
You can use a subquery
SELECT * FROM SFLIGHT AS F INTO WA_SFLIGHT
WHERE SEATSOCC < F~SEATSMAX
AND EXISTS ( SELECT * FROM SPFLI
WHERE CARRID = F~CARRID
AND CONNID = F~CONNID
AND CITYFROM = 'FRANKFURT'
AND CITYTO = 'NEW YORK' )
AND FLDATE BETWEEN '19990101' AND '19990331'.
WRITE: / WA_SFLIGHT-CARRID, WA_SFLIGHT-CONNID,
WA_SFLIGHT-FLDATE.
ENDSELECT.
or simply query the first table and then the second table with select endselect.
select * from table a.
select * from table b into output_table
where b-field1 eq a-field2.
endselect.
or read the data into one internal table loop at it and then query the other table.
Regards,
Shekhar Kulkarni -
Can't write right sql query by two tables
Hello
Everyone,
I am trying to get a sql query by two tables,
table:container
<pre class="jive-pre">
from_dest_id number
ship_from_desc varchar
to_dest_id number
</pre>
table: label_fromat (changeless)
<pre class="jive-pre">
SORT_ORDER number
PREFIX varchar2
VARIABLE_NAME varchar2
SUFFIX varchar2
LF_COMMENT varchar2
</pre>
the sql which i need is
a. table CONTAINER 's each column should have LABLE_FORMAT 's PREFIX before and SUFFIX back ,and these columns is connected
example : the query output should be like this :
<pre class="jive-pre">
PREFIX||from_dest_id||SUFFIX ||PREFIX||ship_from_desc||SUFFIX ||PREFIX|| to_dest_id||SUFFIX
</pre>
every PREFIX and SUFFIX are come from LABEL_FORMAT's column VARIABLE_NAME (they are different)
column SORT_ORDER decide the sequence, for the example above: Column from_dest_id order is 1, ship_from_desc is 2,to_dest_id is 3
b. table LABEL_FORMAT's column VARIABLE_NAME have values ('from_dest_id','ship_from_desc','to_dest_id')
If table CONTAINER only have one record i can do it myself,
But actually it is more than one record,I do not know how to do
May be this should be used PL/SQL,or a Function ,Cursor ,Procedure
I am not good at these
Any tips will be very helpful for me
Thanks
SavenHi, Saven,
Presenting data from multiple rows as a single string is called String Aggregation . This page:
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
shows many ways to do it, suited to different requirements, and different versions of Oracle.
In Oracle 10 (and up) you can do this:
SELECT REPLACE ( SYS_CONNECT_BY_PATH ( f.prefix || ' '
|| CASE f.variable_name
WHEN 'FROM_DEST_ID'
THEN from_dest_id
WHEN 'SHIP_FROM_DESC'
THEN ship_from_desc
WHEN 'TO_DEST_ID'
THEN to_dest_id
END
|| ' '
|| f.suffix
, '~?'
, '~?'
) AS output_txt
FROM container c
CROSS JOIN label_format f
WHERE CONNECT_BY_ISLEAF = 1
START WITH f.sort_order = 1
CONNECT BY f.sort_order = PRIOR f.sort_order + 1
AND c.from_dest_id = PRIOR c.from_dest_id
saven wrote:If table CONTAINER only have one record i can do it myself,
But actually it is more than one record,I do not know how to do In that case, why did you post an example that only has one row in container?
The query above assumes
something in container (I used from_dest_id in the example above) is unique,
you don't mind having a space after prefix and before from_dest_id,
you want one row of output for every row in container, and
you can identify some string ('~?' in the example above) that never occurs in the concatenated data. -
in order to create parent-child relationships, we need to use two tables because some children can have two parents and all parents have more than one children.
this makes tree walking by using the "connect by prior" difficult. has anyone run into something similar and what is the solution?
tiaIf you try to run a hierarchical query, using START WITH,
CONNECTY BY, and PRIOR on a sub-query that contains a join
condition, or on a view that was created using a join condition,
you will get "ORA-01437: cannot have join with CONNECT BY". One
way to get around this problem is to create a new table from the
tables that need to be joined, then run the hierarchical query
on the new table.
For example, first create the new table:
CREATE TABLE new_table AS
SELECT old_table1.column_a, old_table2.column_b
FROM old_table1, old_table2
WHERE old_table1.column_c = old_table2.column_d;
or if you are doing a self-join:
CREATE TABLE new_table AS
SELECT x.column_a, y.column_b
FROM old_table1 x, old_table1 y
WHERE x.column_c = y.column_d;
Then, run the hierarchical query:
SELECT column_a, column_b
FROM new_table
START WITH column_a = 'whatever'
CONNECT BY PRIOR column_b = column_a;If you could post your table structure, some sample data, and a
sample of the desired result, some of us could probably provide
a more specific solution.
Having multiple parents should not create a problem unless the
relationship creates a loop, like if A is a parent of B and B is
a parent of C and C is a parent of A. -
Hi,
I have this problem, How can query a two table?
Table A -> Table B
id table-a_id
name table_b_name
the relationship is one-to-many
How can I get the result?
Hope my question make sense
cheers.
thanks a lot.I bet you have more luck looking for an answer in a SQL forum.
-
I'm using the LabView Database Connectivity Toolset and am using the following query...
UPDATE IndexStation
SET Signal_Size=200
WHERE 'StartTime=12:05:23'
Now the problem is that this command seems to update all rows in the table IndexStation... Not just specifically the row where StartTime=12:05:23
I have tries all sorts of {} [] / ' " around certain characters and column names but it always seems to update all rows...
I've begun to use the SQL query tab in Access to try and narrow down as to why this happens, but no luck!
Any ideas!?
Thanks,
Chris.Chris Walter wrote:
I completely agree about the Microsoft issue.
But it seems no SQL based manual states that { } will provide a Date/Time constant.
Is this an NI only implementation? Because I can't seem to get it to function correctly within LabView or in any SQL query.
Chris.
There is nothing about the database toolkit in terms of SQL syntax that would be NI specific. The database Toolkit simply interfaces to MS ADO/DAO and the actual SQL syntax is usually implemented in the database driver or database itself although I wouldn't be surprised if ADO/DAO does at times munch a bit with that too.
The Database Toolkit definitely does not. So this might be a documentation error indeed. My understanding of SQL syntax is in fact rather limited so not sure which databases might use what delimiters to format date/time values. I know that SQL Server is rather tricky thanks to MS catering for the local date/time format in all their tools and the so called universal date/time format has borked on me on several occasions.
Rolf Kalbermatter
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions -
Dear Expert,
If I want to make queries for two tables, for example I want to make a query for the list or amount of invoices for a certain group of clients with same master records such as geographic location, then how can I make the queries which involves two tables.
Thank you.
RaymondHi,
Use territories to segregate your Business Partners geographycally and then use following query to view doc total of invoices for business partners belongs to a particular territoy,
SELECT T0.DocTotal FROM OINV T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode INNER JOIN OTER T2 ON T1.Territory = T2.territryID WHERE T2.descript =[%0]
Regards,
/Siddiq -
Can we use two table in on report
HI
how to use two different table views in one report.
Regards
Birudug_p_java wrote:
Hello, i would like to ask sthg related to JDBC. I know that we can delete, select, insert, update using JDBC.
But can we create a table?
For example, i may have an html page where sm has the choice to "create a new category for a product", that means that he has to create a new table in the database and he has to insert in a form the characteristics, let's say that he gives the following arguments
Why does that require a new table at all?
A meta data solution is probably better.
Can we do that using JDBC or shall we do it manually? Yes. The syntax can be database and version specific however. And the specifics of how you do that also depend on those. -
Hi all
How to query in two different tables? Should i use the following
SET_BLOCK_PROPERTY('ins1', ONETIME_WHERE, 'serial = ''' || :GLOBAL.CODE || ''''); this is working but for one table if i want for both tables and and it display the related information in main form , eg..tables are referenced by primary key constraint and foreign key.
sarah
Edited by: SarahSarahSarah on Sep 1, 2009 4:59 AMFor the primary forign key tables no need to create two forms use the master detail functionality of forms.
create a Master/Detail form using the DEPARTMENT, EMPLOYEE tables.
DEPARTMENTwill be the Master block and EMPLOYEE will be the Detail block. The join condition between the two tables is where the deptno column of DEPARTMENT is equal to the deptno column of EMPLOYEE .
The following is an outline of the steps:
Create the DEPARTMENT data block and include the all the fields on the form.
Use the Form layout and only display one record at a time.
Go back to the Object Navigator and select the "Data Blocks" tree. Make sure the DEPARTMENT block is not selected and run the Data Block Wizard again.
Create the EMPLOYEE data block and include all of the columns.
For the master/Detail relationship, de-select the "auto" option, use a Join relationship, choose the DEPARTMENT data block as the Master and set EMPLOYEE.DEPTNO= DEPARTMENT.DEPTNO for the join relationship.
In the Layout Wizard for the Dependents data block, display all of the fields
Choose a Tabular style and display 4 up to records at once with 0 space between each record.
Save the form and run the form.
Thanks -
Optimizing the Query joining two tables multiple times
Hi all,
I need to formulate a query where I want to get data from two tables.Here are the table structures and sample data.
Table1
id firstname lastname accountnumber
1 Sridh Peter SP456
2 Gane San SS667
3 Sway patel PP345
Table 2
id attributename attributevalue
1 Manager Mike
1 Lawyer Schwa
1 Server maneka
1 location langur
1 System Novel
2 Manager kane
2 lawyer endun
2 location colrado
3 server queen
3 system elanda
The requirement is I need to generate a report like th follwoing
Accountnumber firstname lastname manager lawyer System Server location
SP456 Sridh Peter Mike schwa Novel maneka langur
SS667 Gane San kane endun colrado
Now I have done this report using a query where I join table1 and table2 multiple times to get the report's data. And that query only works If the user has all attributes.If any one attribut is missing it wont work.Can some onehelp me with this.
The query i am using looks like this.
select a.accountnumber,a.firstname,a.lastname,b.attributevalue,c.attributevalue, d.attributevalue, e.attributevalue,f.attributevalue from table1 a,table2 b where a.id=b.id and a.id=c.id and a.id=d.id and a.id=e.id and a.id=f.id and b.attributename ='manager' and c.attributename ='lawyer' and d.attributename='system' and e.attributename='server' and f.attributename='location'
this query works well if a user has all attributes ,if any one is missing he is not shown in the report.Can some one suggest me a good way of querying than this.
The query I am using is also taking lot of time..I think I have explained my question well ,please reply if you have questions.
Thanks for reading till here patiently,
Pandu....if this .....
<DIV><B>
<P><FONT face=Tahoma size=2>select</FONT></B><FONT size=2><FONT face=Tahoma>
Accountnumber||</FONT><FONT face=Tahoma>' '||firstname||' '||lastname||'
'||manager||' '||<B>System</B>||' '||Server||' '</FONT></FONT><FONT face=Tahoma
size=2>||location<BR><B>from<SPAN
class=940214002-13042006> </SPAN></B>(<B>select</B>
* <BR><B><SPAN
class=940214002-13042006>
</SPAN>from<SPAN class=940214002-13042006> </SPAN></B>(<B>select</B> '1'
id, 'Sridh' firstname, 'Peter' lastname, 'SP456'</FONT><FONT face=Tahoma size=2>
accountnumber <B>from</B> dual <B>union</B><BR><B><SPAN
class=940214002-13042006>
</SPAN>select</B> '2' id, 'Gane' firstname, 'San' lastname, 'SS667'</FONT><FONT
face=Tahoma size=2> accountnumber <B>from</B> dual <B>union</B><BR><B><SPAN
class=940214002-13042006> </SPAN>select</B>
'3' id, 'Sway' firstname, 'patel' lastname, 'PP345'</FONT><FONT face=Tahoma
size=2> accountnumber <B>from</B> dual) x,<BR><BR><SPAN
class=940214002-13042006>
</SPAN>(<B>select</B> * <BR><B><SPAN
class=940214002-13042006> </SPAN>from</B>
(<B>select</B> id,<BR><SPAN
class=940214002-13042006> </SPAN>attributename,<BR><SPAN
class=940214002-13042006>
</SPAN>lead(attributevalue,0</FONT><FONT face=Tahoma size=2>) over (<SPAN
class=940214002-13042006><STRONG>partition by </STRONG>id </SPAN><B>order</B>
<B>by</B> id) <B>as</B> Manager,<BR><SPAN
class=940214002-13042006>
</SPAN>lead(attributevalue,1</FONT><FONT face=Tahoma size=2>) over (<B><SPAN
class=940214002-13042006><STRONG>partition by </STRONG>id </SPAN><B>order</B>
<B>by</B> id</B>) <B>as</B> Lawyer,<BR><SPAN
class=940214002-13042006>
</SPAN>lead(attributevalue,2</FONT><FONT face=Tahoma size=2>) over (<B><SPAN
class=940214002-13042006><STRONG>partition by </STRONG>id </SPAN><B>order</B>
<B>by</B> id</B>) <B>as</B> System,<BR><SPAN
class=940214002-13042006>
</SPAN>lead(attributevalue,3</FONT><FONT face=Tahoma size=2>) over (<B><SPAN
class=940214002-13042006><STRONG>partition by </STRONG>id </SPAN><B>order</B>
<B>by</B> id<SPAN class=940214002-13042006>)</SPAN></B> <B>as</B>
Server,<BR><SPAN
class=940214002-13042006>
</SPAN>lead(attributevalue,4</FONT><FONT size=2><FONT face=Tahoma>) over
(<B><SPAN class=940214002-13042006><STRONG>partition by </STRONG>id
</SPAN><B>order</B> <B>by</B> id</B>) <B>as</B> Location<BR><B><SPAN
class=940214002-13042006>
</SPAN>from</B> (<B>select</B> *<SPAN class=940214002-13042006>
</SPAN></FONT></FONT><FONT size=+0><FONT face=Tahoma><FONT size=2><B>from</B>
(<B>select</B> '1' id, 'Manager' attributename, 'Mike'</FONT></FONT></FONT><FONT
face=Tahoma size=2> attributevalue <B>from</B> dual <B>union</B><BR><B><SPAN
class=940214002-13042006> </SPAN>select</B>
'1' id, 'Lawyer' attributename, 'Schwa'</FONT><FONT face=Tahoma size=2>
attributevalue <B>from</B> dual <B>union</B><BR><B><SPAN
class=940214002-13042006> </SPAN>select</B>
'1' id, 'Server' attributename, 'maneka'</FONT><FONT face=Tahoma size=2>
attributevalue <B>from</B> dual <B>union</B><BR><B><SPAN
class=940214002-13042006>
</SPAN>select</B> '1' id, 'location' attributename, 'langur'</FONT><FONT
face=Tahoma size=2> attributevalue <B>from</B> dual <B>union</B><BR><B><SPAN
class=940214002-13042006>
</SPAN>select</B> '1' id, 'System' attributename, 'Novel'</FONT><FONT
face=Tahoma size=2> attributevalue <B>from</B> dual <B>union</B><BR><B><SPAN
class=940214002-13042006> </SPAN>select</B>
'2' id, 'Manager' attributename, 'kane'</FONT><FONT face=Tahoma size=2>
attributevalue <B>from</B> dual <B>union</B><BR><B><SPAN
class=940214002-13042006> </SPAN>select</B>
'2' id, 'lawyer' attributename, 'endun'</FONT><FONT face=Tahoma size=2>
attributevalue <B>from</B> dual <B>union</B><BR><B><SPAN
class=940214002-13042006>
</SPAN>select</B> '2' id, 'location' attributename, 'colrado'</FONT><FONT
face=Tahoma size=2> attributevalue <B>from</B> dual <B>union</B><BR><B><SPAN
class=940214002-13042006> </SPAN>select</B>
'3' id, 'server' attributename, 'queen'</FONT><FONT face=Tahoma size=2>
attributevalue <B>from</B> dual <B>union</B><BR><B><SPAN
class=940214002-13042006> </SPAN>select</B>
'3' id, 'system' attributename, 'elanda'</FONT><FONT face=Tahoma size=2>
attributevalue <B>from</B> dual)<BR><B><SPAN
class=940214002-13042006> </SPAN>order</B>
<B>by</B> id, (<B>case</B> <B>when</B> attributename='Manager' <B>then</B>
1</FONT><FONT face=Tahoma size=2> <BR><B><SPAN
class=940214002-13042006>
</SPAN>when</B> attributename='Lawyer' <B>then</B> 2</FONT><FONT face=Tahoma
size=2> <BR><B><SPAN
class=940214002-13042006>
</SPAN>when</B> attributename='System' <B>then</B> 3</FONT><FONT face=Tahoma
size=2> <BR><B><SPAN
class=940214002-13042006>
</SPAN>when</B> attributename='Server' <B>then</B> 4</FONT><FONT face=Tahoma
size=2> <BR><B><SPAN
class=940214002-13042006>
</SPAN>when</B> attributename='Location' <B>then</B> 5</FONT><FONT
face=Tahoma><FONT size=2> <B>end</B>) <B>asc</B>))<BR><B><SPAN
class=940214002-13042006>
</SPAN>where</B> attributename='Manager'</FONT></FONT><FONT face=Tahoma size=2>)
y<BR><B>where</B> x.id(+)=y.id)</FONT></P></DIV>
< Jonel -
How to structure report using two tables...
Hi all,
CR 2011; SLQ 2008
I have a report that uses several tables but is essentially grouped into two "types" of sources.
tbl.Produkte holds current data basically about stock levels, "real time"
tbl.Log holds stock movement history.
The commonality between the tables is StockID, which is a distinct column, but is an ID that is used to track based on three attributes: Product, WidthHeight, and ContentCnt. All three of these are columns unto themselves, but are not available in all tables, so I need to rely on StockID for fetches.
Now I need to report by Product and WidthHeight. I look to tbl.Produkte for some information such as Stock level, Average ContentCnt, and Reservations on Stock.
Ideally on the same line, I'm looking to report on Average Monthly Usage, derived information coming from the tbl.Log.
I seem to think I need a subreport to do this, but end up getting multiple occurances of the subreport when the StockID occurs multiple times in tbl.Produkte. This is something I always seem to run into when I use a subreport, and I haven't been able to wrap my brain around it yet. I'm handy enough with queries, but trying to use Commands to limit the data I'm picking seems to offer no better solutions.
Anyone have insights as to what's wrong with my approach?
To recap:
I need a summary line by Product - WidthHeight
Data consists of multiple rows coming from tbl.Produkte and multiple rows coming from tbl.Log
Tables are essentialy unrelated in content but can be linked by StockID
Need to elliminate multiple occurences of data coming from tbl.Log when there are multiple rows in tbl.Produkte
Hope I haven't made complete mud of my predicament...
Thanks you - MattHi,
The code in my previous post was cut and pasted from my project. It's in a command and work fine by itself, but as soon as I add more tables, I get the ODBC error.
I'm guessing I need another approach. I realize my original description was incomplete.
Basically the meat consists of three tables LG_PRODUKTE, LG_LAGERORTE, and LG_LOGBUCH.
The common field among the three is ID, which is a Stock ID that is uniquely comprised of Product, Size, and Contents(Qty)
LG_PRODUKTE is the basic Product listing. ID is unique in this table. I need this for completeness and extended product data.
LG_LAGERORTE is the Inventory. ID can occur multiple times. I need this to compile current Inventory.
LG_LOGBUCH is the History. ID can occur multiple times. I need this to compile past usage.
I have tried both Inner and Left joins from LG_PRODUKTE to LG_LAGERORTE and feom LG_PRODUKTE to LG_LOGBUCH
My Groupings are is:
1 - Product
2 - Size
3 - ID
Detail
My primary issue is that I can't just report at the ID level because Contents(Qty) is really just a detail of the Product/Size.
I need to summarize at the size level (also Product and Grand)
At this level I need to pull in summary information from LG_LAGERORTE and LG_LOGBUCH, independantly, based on data linked on ID.
Right now, I'm going to try subreports at Footer 2A for LG_LAGERORTE data, 2B for LG_LOGBUCH, passing parameters to 2C for a combined line...
Can't seem to pin down the juggling... -
Reg:Using Two Table controls in one screen
Dear All,
I created two tables in a screen such that both the table fields are of Input fields type .I created first table which will
accept the inputs and below it I created another Table which is also of Input field type.But when I execute the component I am getting only first Table in Input mode and the other Table is in Disable mode.
What can be the problem??hi
other Table is in Disable mode.
check that u have unticked the READ ONLY property of ur UI
also check if u have binded the ENABLE property of ur table UI to WDY_BOOLEAN in some method
and u r setting it to 'X'
in the OnToggle event of ur Checkbox , set this attribute to 'X to make the checkbox ticked
in the OnToggle event of ur Checkbox , set this attribute to ' ' to make the checkbox un ticked
DATA lo_nd_cn_node TYPE REF TO if_wd_context_node.
DATA lo_el_cn_node TYPE REF TO if_wd_context_element.
DATA ls_cn_node TYPE wd_this->element_cn_node .
DATA lv_attr LIKE ls_city-ca_attr.
* navigate from <CONTEXT> to <CN_VISIBLE> via lead selection
lo_nd_node = wd_context->get_child_node( name = wd_this->wdctx_ca_attr).
* get element via lead selection
lo_el_cn_node = lo_nd_cn_node->get_element( ).
* set single attribute
lo_el_cn_node->set_attribute(
EXPORTING
name = `CA_ATTR`
value = ' ' ).
// set attribute CA_ATTR under CN_NODE to ' '
// this will make the table UI control disabled
// this is a code generated thru code wizard ( control +f7) , read context node/attribute
// use SET_ATTRIBUTE method
regards,
amit -
I have the following two tables:
Asset_Issued
Asset_Type_ID
Assigned To
1
Ram
2
Ram
3
Ram
4
Ram
5
Ram
1
Raju
3
Raju
5
Raju
1
Rajesh
3
Rajesh
2
Rajesh
Asset_Type
Asset_Type_ID
Asset_Name
1
Laptop
2
Desktop
3
Mouse
4
Keyboard
5
Monitor
Can anyone help me with the query that will give the following result.
Asset_Issued_Count
Asset_Name
Count
Laptop
3
Desktop
2
Mouse
3
Keyboard
1
Monitor
1I think your OUTPUT COUNT for MONITOR should be 2 and not 1. Try the below.
WITH ASSET_ISSED(ASSET_TYPE_ID,ASSIGNED_TO) AS(
SELECT 1,'Ram' FROM DUAL UNION ALL
SELECT 2,'Ram' FROM DUAL UNION ALL
SELECT 3,'Ram' FROM DUAL UNION ALL
SELECT 4,'Ram' FROM DUAL UNION ALL
SELECT 5,'Ram' FROM DUAL UNION ALL
SELECT 1,'Raju' FROM DUAL UNION ALL
SELECT 3,'Raju' FROM DUAL UNION ALL
SELECT 5,'Raju' FROM DUAL UNION ALL
SELECT 1,'Rajesh' FROM DUAL UNION ALL
SELECT 3,'Rajesh' FROM DUAL UNION ALL
SELECT 2,'Rajesh' FROM DUAL),
ASSET_TYPE(ASSET_TYPE_ID,ASSET_NAME) AS
(SELECT 1,'Laptop' FROM DUAL UNION ALL
SELECT 2,'Desktop' FROM DUAL UNION ALL
SELECT 3,'Mouse' FROM DUAL UNION ALL
SELECT 4,'Keyboard' FROM DUAL UNION ALL
SELECT 5,'Monitor' FROM DUAL)
SELECT ASSET_NAME,
COUNT(1)
FROM
ASSET_ISSED T1,
ASSET_TYPE T2
WHERE T1.ASSET_TYPE_ID=T2.ASSET_TYPE_ID
GROUP BY T2.ASSET_NAME;
OUTPUT:
ASSET_NA COUNT(1)
Desktop 2
Laptop 3
Mouse 3
Keyboard 1
Monitor 2 -
Need to update multiple columns using another table
I have 2 tables. and i need to update rows of 1 table using another table
Table1
Serial_no. payment_date Payment_amt
101 22/11/2010 150
101 18/03/2011 355
102 15/04/2011 488
103 20/05/2011 178
102 14/06/2011 269
101 28/06/2011 505
Table2
Serial_no Charge_amt Last_paymt_dt Last_paymt_amt
101 255
102 648
103 475
I want to update Last_paymt_dt and Last_paymt_amt of table2 using Table1, I have written following update statement but it gives error that single row subquery return multiple row.
Update Table2
set (Last_paymt_dt,Last_paymt_amt) = (select max(payment_date, payment_amt) from table1
where table1.Serial_no = table2.Serial_no group by payment_amt)
kindly suggest how should i update.SQL> select * from table1
2 /
SERIAL_NO PAYMENT_DA PAYMENT_AMT
101 22/11/2010 150
101 18/03/2011 355
102 15/04/2011 488
103 20/05/2011 178
102 14/06/2011 269
101 28/06/2011 505
6 rows selected.
SQL> select * from table2
2 /
SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
101 255
102 648
103 475
SQL> update table2
2 set (last_paymt_dt,last_paymt_amt) = (
3 select max(payment_date),
4 max(payment_amt) keep(dense_rank last order by payment_date)
5 from table1
6 where table1.serial_no = table2.serial_no
7 )
8 /
3 rows updated.
SQL> select * from table2
2 /
SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
101 255 28/06/2011 505
102 648 14/06/2011 269
103 475 20/05/2011 178
SQL> SY. -
hi,
i have two table for emp attendance and leave .
1 table name --emp_att
emp_id------- number;
att_date -----date;
status ---------varchar(30);
in_time -------timestamp;
out_time -----timestaemp;
session--------- varchar2(12)
2--emp_leave
emp_id -------- number;
leave_date ---- date
leave type----- varchar2(17);
session -----------varchar2(12);
Here Leave Type ------SL,CL,PL THESE ARE LEAVE
now i want a report like
eg :-
emp_id---DATE ----STATUS----IN TIME----OUT TIME------ SESSION
101 01-JAN-2009 PRESENT 09:35 AM 3:56 PM 2009-2010
102 01-JAN-2009 SL 09:20 AM 3:30 PM 2009-2010
103 01-JAN-2009 PRESENT 09:35 AM 3:30 PM 2009-2010
104 01-JAN-2009 SL 09:15 AM 3:56 PM 2009-2010
105 01-JAN-2009 PRESENT 09:35 AM 3:56 PM 2009-2010
106 01-JAN-2009 PRESENT 09:35 AM 3:30 PM 2009-2010
107 01-JAN-2009 CL 09:35 AM 3:56 PM 2009-2010
108 01-JAN-2009 PRESENT 09:40 AM 3:30 PM 2009-2010
THANKS
Manojwhat happens if the employee is absent do we still have records in emp_att table or there is data in emp_leave only.Why are you asking us? It's your application, you should know the business logic.
I'm afraid I still don't understand what your question is. You want us to spend our time answering your question. We can't do that if we don't understand your point or the application you're working on. You need to spend an equal amount of time framing your post.
Please try again.
Cheers, APC
blog: http://radiofreetooting.blogspot.com
Maybe you are looking for
-
Formatting a Lacie Hard drive for Mac
Is there anyone who can help me format my Lacie 320GB external hard drive for my Mac. Currently it is formatted for MS-DOS. I've read the manual inside and tried what it says but have got nowhere. Any suggestions would be much appreciated. Many thank
-
How can I recover my playlists?
My hard drive fried, and after I received a new one I saw that though my library was intact, my playlists disappeared. They are on my iPhone 5 - worst case, can I upload from there?
-
MacBookPro vs PowerBook Capturing Working w/HDV - CardBus vs no ExpressCard
I have seen the benchmarks and the posts here, and it is clear, but for the issues below, I should be getting a MacBook Pro now that my older PowerBook has run into issues. Once footage is captured it seems to be a no-brainer (This thread http://disc
-
2 days ago both mine and my daughter's macs stopped being able to open up the apple start up page
2 days ago both mine and my daughter's macs stopped being able to open up the apple start up page, search google, yahoo, facebook and many other sites. Pictures won't download on sites and we are redirected to http://www.website-unavailable.com/main?
-
10.6.3-compatible MacBook won't upgrade w/o re-partition
Intel Core2Duo, 2Gb mem, 215Gb free, File System: Journaled HFS+ Using "MAC OS X V10.6.3 RETAIL" CD: The upgrade begins with a request to Restart. After the language selection, then "To set up the installation of Snow Leopard, click Continue",then th