[Help] Join the query from 3 tables
Hi, I'm new to database. I have a question about joining 3 tables, forgive me for my bad English.My paintings look like this
Table 1: person (id, firstname, lastname)
Table 2: AssignPersonAddress (id, personid, addressid, type)
Table 3: address (id, phone, street, etc.)
I need AssignPersonAddress table, because in my data structure, a person may have more than 1 address and address type must be registered (for example: private, work)
I want to do a select query to the State any person with his private phone and work phone, like this.
NOBODY | PRIVATE | WORK
Right now my query looks like this
select p.name , a1.tel AS Private, a2.tel AS Work
from person p,
addresse a1 ,
AssignPersonAddress apd1,
AssignPersonAddress apd2,
addresse a2
where p.id = apd1.person (+)
and apd1.adresse = a1.id
and apd1.art = 'Private'
and p.objectid = apd2.person (+)
and apd2.adresse = a2.id
and apd2.art = 'Work'
the problem is that I only get the person who has a private address and the job. But what I want is all anyone no matter if the person has only 1 or 2 address.As you can see I put the left outer join in where condition, but I always get the wrong result.
THX in advance
Danny
Published by: raitodn on October 1st, 2009 03:51
Published by: raitodn on October 1st, 2009 04:12
Tags: Database
Similar Questions
-
Help with the query to select only one record from the result set in double
Hello
Please help with the query. Version of Oracle database we use is 10g R2.
I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec
ID Org DF Sec Sub-Sec (163) CQ CPDM CPDM HD (163) PC ENG ENG ENG (163) CQ ASIC ASIC IS 8888 TS TAC TAC TAC (163) TS HE HE SW 6789 CQ INFO INFO FOS 6789 PC SECSYS SECSYS INFO1 6789 TS SECSYS SECSYS INFO2 9009 PC BMS BMS BMS1 My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.
ID DSB DF SEC Sub-Sec (163) CQ CPDM CPDM HD 8888 TS TAC TAC TAC 6789 CQ INFO INFO FOS 9009 PC BMS BMS BMS1 Thank you
Orton
Hello
This sounds like a job for ROW_NUMBER:
WITH got_r_num AS
(
SELECT id, DSB, df, s, sub_sec org
ROW_NUMBER () OVER (PARTITION BY ID.
ORDER BY org
) AS r_num
OF view_x
)
SELECT id, DSB, df, sub_sec s,
OF got_r_num
WHERE r_num = 1
;
He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data. (I know that you said that you were a view selection. Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places. (I didn't quite understand the explanation above. I don't know why you want toID ORG DF DRY SUB_SEC
-- --- -- --- -------
1234 CQ DPRK DPRK HD
and is not
1234 IS CQ ASIC, ASIC
or
TS 1234 IT IT SW
or
1234 CQ ASIC ASIC HD
)
If you change the query at all, post your modified version.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
-
need help with the query, thx
Hello
I need a little help with the query I have to write;
the table has 4 columns:
what I am asking is the following result: salary according to the latest available yearcol1 col2 col3 col4 emp_name empl_id salary year content of data: col1 col2 col3 col4 smith 12 1200 1999 smith 12 1340 2000 smith 12 1500 2001 jones 13 1550 1999 jones 13 1600 2000 aron 14 1200 2002
i.e.
ID appreciate some guidance on how to achievesmith 12 1500 2001 jones 13 1600 2000 aron 14 1200 2002
Thank you
Rgdsselect *from (select col1, col2,col3, col4,row_number() over(partition by col1 order by col4 desc) rn from
) where rn=1 -
Join the query/right /.
Join the query/right /.
In the end, we try to find the ZZOMTAB. STAFF
I know the value exists because I have asked this by
K_NO
By this query
Select
ZZOMTAB. STAFF
Of
ZZOMTAB
where
K_NO = 146735
so that's where
But what I'm left with app_no = 79219
I tried this query and it does not work (no value in the ZZOMTAB. STAFF)
SELECT
ZZOMTAB. STAFF
OF TKASERTAB
ZZOMTAB RIGHT JOIN
ON TKASERTAB. K_NO = ZZOMTAB. K_NO
APPTAB RIGHT JOIN
ON TKASERTAB.app_no = APPTAB.app_no
where
APPTAB.app_no = 79219
the value that I'm trying to get is ZZOMTAB. STAFF
and I give myself with app_no = 79219
the tables are
the tables are
TKASERTAB with K_NO and APPNO columns
APPTAB with column APPNO
and
ZZOMTAB with K_NO
I'm trying to get the value of ZZOMTAB. STAFF
Can anyone help?
Thanks in adv
Try to move the APPTAB.app_no = 79219 WHERE clause and put it in your RIGHT JOIN.
SELECT
ZZOMTAB. STAFF
OF TKASERTAB
ZZOMTAB RIGHT JOIN
ON TKASERTAB. K_NO = ZZOMTAB. K_NO
APPTAB RIGHT JOIN
ON TKASERTAB.app_no = APPTAB.app_no
AND APPTAB.app_no = 79219Phil
-
help in registration of the records from two tables
HI: I have two tables joined the first field. The field is the primary key in the first table. Need help listing records from both tables with each a line/record results.
I want to print each record in the table of EVENTS such as a line and the corresponding records in EVENT_UPDATES as a line like this recordcreate table EVENTS ( event_key varchar2(64) primary key, event_description varchar2(64), create_time int ); create table EVENT_UPDATES ( event_key varchar2(64) NOT NULL , update_description varchar2(64), update_time int ); insert into EVENTS values('Event1', 'This is event1', 1); insert into EVENT_UPDATES values('Event1', 'Ticket created', 3); insert into EVENT_UPDATES values('Event1', 'Event cleared', 10); insert into EVENTS values('Event2', 'This is event2', 4); insert into EVENT_UPDATES values('Event2', 'Ticket created', 6); insert into EVENT_UPDATES values('Event2', 'Event cleared', 8);
TIAEvent1 1 This is event1 3 Ticket created 10 Event cleared Event2 4 This is event2 6 Ticket created 8 Event cleared
Raviselect case weight when 1 then event_key end key, time_val, description from ( select event_key, create_time time_val, event_description description, 1 weight from events union all select event_key, update_time, update_description, 2 weight from event_updates ) order by event_key, weight / KEY TIME_VAL DESCRIPTION ---------- ---------- ------------------------- Event1 1 This is event1 3 Ticket created 10 Event cleared Event2 4 This is event2 6 Ticket created 8 Event cleared 6 rows selected. SQL>
SY.
-
Join the execution of several Tables Plan
Try to understand the query execution plan:
So he needs to MERGE between DEPARTMENTS (that has been sorted by index) JOIN and (here's the part confusing...) LOCATIONS including oracle used HASH JOIN (?) to bring the information from and then sort the opinion generated by the system that has been created...?HR> SELECT e.last_name , d.department_name, l.city 2 FROM employees e, departments d , locations l 3 WHERE e.department_id = d.department_id 4 AND 5 d.location_id = l.location_id; Execution Plan ---------------------------------------------------------- Plan hash value: 1235509609 -------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 106 | 4346 | 9 (23)| 00:00:01 | |* 1 | HASH JOIN | | 106 | 4346 | 9 (23)| 00:00:01 | | 2 | MERGE JOIN | | 27 | 837 | 6 (34)| 00:00:01 | | 3 | TABLE ACCESS BY INDEX ROWID| DEPARTMENTS | 27 | 513 | 2 (0)| 00:00:01 | | 4 | INDEX FULL SCAN | DEPT_LOCATION_IX | 27 | | 1 (0)| 00:00:01 | |* 5 | SORT JOIN | | 23 | 276 | 4 (50)| 00:00:01 | | 6 | VIEW | index$_join$_003 | 23 | 276 | 3 (34)| 00:00:01 | |* 7 | HASH JOIN | | | | | | | 8 | INDEX FAST FULL SCAN | LOC_CITY_IX | 23 | 276 | 1 (0)| 00:00:01 | | 9 | INDEX FAST FULL SCAN | LOC_ID_PK | 23 | 276 | 1 (0)| 00:00:01 | | 10 | TABLE ACCESS FULL | EMPLOYEES | 107 | 1070 | 3 (0)| 00:00:01 | --------------------------------------------------------------------------------------------------
Is that this HASH JOIN to step 7 only refers to a view that is generated by the system that oracle had to sort and not actually HASH JOIN
between two tables?
Thanks much for you patienceHello
Perhaps, it helps to understand things better if we walk in the plan.
Plans have a hierarchical structure (which is translated graphically by fingerprints). Operating needs parent all the children completed operations before it can do its job (which is generally combining lines with children in one way or another).
Another point is that joins can have anything like their entries, tables not only. That is a hash join can join an index for an index or a table to an index, or then to join a table results of hash one another and so on and so forth.
With this in mind, we can go back on what is happening here step by step:
The needs of the join by hash (1) (2) and (10) to finish. (10) is a basic operation, since a table scan depends on nothing else, but merge join handset (2) (3) and (5), who both are complex operations (i.e. dependent on one or more children). Specifically, lines (3) from the DEPARTMENTS table using ROWID obtained from a full analysis of the index of DEPT_LOCATION_IX (4), (5) is simply lines join hash (7) and sorted in the order required.
I hope this helps.
Best regards
NikolaiPublished by: Nikolay Savvinov on January 26, 2012 05:26
-
Join the query - confused behavior
Hello.. I need to make a join on four tables and select one data tables. The query is as below,
SELECT THE VIRTUAL MACHINE. SEGMENT, VM.CA, VM. PR, VM. BP, VM. TERM_ID, VM. TL v_mlr_cable VM, v_neicode NEI, v_mlr MLR, v_fibre_ntwk_type FIBER WHERE MLR.master_key = 62 AND MLR.dslam_tid = NEI.id AND NEI.type = 'OLT' AND MLR.ntwk_type = FIBRE.id AND MLR.master_key = VM.master_key;
This query works very well. I want to change the query to have an OR condition by combining certain conditions in the WHERE clause as below,
SELECT THE VIRTUAL MACHINE. SEGMENT, VM.CA, VM. PR, VM. BP, VM. TERM_ID, VM. TL v_mlr_cable VM, v_neicode NEI, v_mlr MLR, v_fibre_ntwk_type FIBER WHERE MLR.master_key = 62 AND ((MLR.dslam_tid = NEI.id ET NEI.type = 'OLT') or MLR.ntwk_type = FIBRE.id) AND MLR.master_key = VM.master_key;
This translates into several duplicates of the correct result lines (about 93 272 rows).
I suspect this is a unwanted Cartesian product.
I am limited to use a 'different' because my application performs custom, so 'distinct' query analysis is out of the option.
I struggle to understand the result of this query. You can help... ! Thanks in advance.
My database: Oracle Enterprise Edition 10.2.0.2.0
Published by: vanessa on June 9, 2011 12:49 AMHello
Can hide you the SELECT DISTINCT in a subquery, like this:
SELECT * FROM ( SELECT DISTINCT VM.SEGMENT, ... );
or in a view?
If this is not the case, use GROUP BY. The GROUP BY clause contains all the columns in the SELECT clause.
You could also re - write the query to use EXISTS or IN, instead of a jon.
For example:SELECT SEGMENT , CA , PR , BP , TERM_ID , TL FROM v_mlr_cable vm WHERE master_key = 62 AND EXISTS ( SELECT 0 FROM v_neicode NEI , v_mlr MLR , v_fibre_ntwk_type FIBRE WHERE MLR.master_key = vm.master_key AND ( ( MLR.dslam_tid = NEI.id AND NEI.type = 'OLT' ) OR MLR.ntwk_type = FIBRE.id ) ) ;
Do you think it is easier to read and understand the code formatted, as the query above, or unformatted, as what you posted?
Who do you think will encourage people to read your question and provide accurate responses?
Never write, not to mention NPA, not formatted.I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) of all the tables and the results desired from these data.
Explain how you get these results from these data.
Always tell what version of Oracle you are using. -
need help with the query: (Frank)
Hi Frank,.
I have the oracle 8 database.
I have the following table with the data structure:
TABLE P (PID, PNAME, COLOR)
PRIMARY KEY: PID
CAT TABLE (SID, PID, COST)PID Pname Color p1........... Red P2................. green p3............... blue p4 .................. red
KEY: SID MAIN + PID
KEY REFERENCE: SID REFERENCE S.SID
PID P.PID REFERENCES
now my question is:Sid Pid COst.... S1 P1 S2 P2 S3 P3 S1 P4 S2 p1 S3 p1
I want to find the SIDS of suppliers that provide a red and a green part
for this I used the following query, but it gives the result worng...
can help me please in this way to get this...
select sid from cat where pid in (select pid from p where color= 'red' union select pid from p where color = 'gren') group by sid having count(pid) >= 2
Hello
Jojo wrote:
Hi Frank,.It would be nice if someone with a different name helped you? Do not restrict yourself by addressing someone in particular in your subject line or the first message.
I have the oracle 8 database.
I have the following table with the data structure:TABLE P (PID, PNAME, COLOR)
PRIMARY KEY: PIDPID Pname Color p1........... Red P2................. green p3............... blue p4 .................. red
CAT TABLE (SID, PID, COST)
KEY: SID MAIN + PID
KEY REFERENCE: SID REFERENCE S.SID
PID P.PID REFERENCESSid Pid COst.... S1 P1 S2 P2 S3 P3 S1 P4 S2 p1 S3 p1
now my question is:
I want to find the SIDS of suppliers that provide a red and a green partfor this I used the following query, but it gives the result worng...
can help me please in this way to get this...
select sid from cat where pid in (select pid from p where color= 'red' union select pid from p where color = 'gren') group by sid having count(pid) >= 2
You don't like what is the number of lines with a pid; If you had 20 rows all said 'p1', that would be good enough. The number of distinct colors of the whole ('red', 'green') is what is important.
Avoid the UNION when there is a simple alternative. The UNION tends to be slow.You can use a join instead, like this:
SELECT c.sid FROM cat c , p WHERE p.pid = c.pid AND p.color IN ('red', 'green') GROUP BY c.sid HAVING COUNT (DISTINCT p.color) = 2 ;
If you would care to post CREATE TABLE and INSERT statements for the sample data and the results that you want from this data, then I could test this.
Published by: Frank Kulash, January 10, 2011 15:25
-
Problem with case when try to alter the query from siimple
Hello PL/SQL gurus and Experts.
I'm stuck with a question (can be simple), but not gettings all headsway.
value returns is as - 1.46select 365/day_num_yr Anul_Fact from Date where date_dt = trunc(sysdate -1)
need to write it in the form of case (I have to multiply it to some other outer query), I want to store variable ina and then use the same in an outside -.
but when use the following syntax, then it always returns 0 and not the same output returned by the query above without the scabbard.
Help kindly, I appericate your time and effort in advance.select (case when date_dt =trunc(sysdate -1) then 365/day_num_yr else 0 END) Anul_Fact
user555994 wrote:
Problem is that I do not get the output as 1.46, even the output is coming like the 0 only if using the query - nextselect /*date_dt, sysdate - 1 prev_dt, trunc(sysdate - 1) trunc_prev_dt,*/ case when date_dt = trunc(sysdate -1) then 365/day_num_yr else 0 end num_day from date_dim;
Completely, which seems to be a question of DATA. Have you checked if the table contains data for DATE_DT = SYSDATE - 1? Can you check if the data stored do not have hours and Minutes stored?
Although I have provided examples of data, which is the same as the data in my main table and once I used the previous solution you provided and then also gives the result as same as those mentioned by you.
I think it's something like -
select date_dt, sysdate - 1 prev_dt, trunc(sysdate - 1) trunc_prev_dt, case when date_dt = trunc(sysdate -1) then 366/day_num_yr where day_num_yr=(select day_num_yr from date_dim where date_dt = trunc(sysdate -1)) else 0 end num_day from date_dim;
Once we get the day_num_yr then he deviding by 366/day_num_yr :(
but he does not like throwing an error ORA-95 - missing keywordYes, it does not work
-case when date_dt = trunc (sysdate-1) then 366/day_num_yr where day_num_yr = (select day_num_yr from the date_dim where date_dt = trunc (sysdate-1))
due to a syntax of alien.
I don't think that you really need. I already said, with the data in your Table, you will be having only * 1 * record with a Non - zero value. Thus, simply apply a filter to extract the corresponding record SYSDATE - 1 and you should get an output which is Non-zero. If you apply a where predicate, then would not need you a CASE statement. You can directly use something like below:select date_dt, sysdate - 1 prev_dt, trunc(sysdate - 1) trunc_prev_dt, 365 / day_num_yr num_day from t4 where date_dt = trunc(sysdate - 1);
Published by: Jen K, September 7, 2012 16:00
-
Please help improve the query with the analytic function
The mentioned below query takes about 10 hours to complete (10.2.0.4).
There are 3 tables (table t has a relationship 1: n with table e and k table also has a relationship 1: n with table e).
Table a contains 200,000 lines. (this table is truncated and inserted several times a week)
E table contains rows of 1Mio.
K table contains rows of 170Mio.
I need a query that takes the latest 3 posts for a given t_id:drop table t; create table t ( t_id number, constraint t_pk primary key (t_id) ); drop table e; create table e ( e_id number, e_doc nvarchar2(16), e_date date, constraint e_pk primary key (e_id) ); drop table k; create table k ( t_id number, e_id number ); create unique index k_i1 on k(t_id, e_id); exec dbms_stats.gather_table_stats(user, 'T'); exec dbms_stats.gather_table_stats(user, 'K'); exec dbms_stats.gather_table_stats(user, 'E'); -- Sample data: insert into t(t_id) values (100); insert into t(t_id) values (101); insert into t(t_id) values (102); insert into t(t_id) values (103); insert into e(e_id, e_doc, e_date) values (200, 'doc 200', to_date('01.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (201, 'doc 201', to_date('02.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (202, 'doc 202', to_date('03.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (203, 'doc 203', to_date('04.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (204, 'doc 204', to_date('05.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (205, 'doc 205', to_date('06.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (206, 'doc 206', to_date('07.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (207, 'doc 207', to_date('08.01.2010', 'DD.MM.YYYY')); insert into k(t_id, e_id) values (100, 200); insert into k(t_id, e_id) values (100, 201); insert into k(t_id, e_id) values (100, 202); insert into k(t_id, e_id) values (100, 203); insert into k(t_id, e_id) values (101, 203); insert into k(t_id, e_id) values (101, 204); select k.t_id, e.e_date, e.e_id, e.e_doc from e, k, t where k.e_id = e.e_id and k.t_id = t.t_id order by k.t_id, e.e_date desc; T_ID E_DATE E_ID E_DOC ---------- -------- ---------- ---------------- 100 04.01.10 203 doc 203 100 03.01.10 202 doc 202 100 02.01.10 201 doc 201 100 01.01.10 200 doc 200 101 05.01.10 204 doc 204 101 04.01.10 203 doc 203
The example query takes several hours in production.T_ID E_DOC_LIST ---------- ----------------------- 100 doc 200/doc 201/doc 202 101 doc 203/doc 204 Sample query: select t_id, e_doc_list from ( select k.t_id, row_number() over(partition by k.t_id order by k.t_id, e.e_date desc) r_num, rtrim( lag(e.e_doc, 0) over(partition by k.t_id order by k.t_id, e.e_date) || '/' || lag(e.e_doc, 1) over(partition by k.t_id order by k.t_id, e.e_date) || '/' || lag(e.e_doc, 2) over(partition by k.t_id order by k.t_id, e.e_date), '/') e_doc_list from e, k, t where k.e_id = e.e_id and k.t_id = t.t_id order by k.t_id, e.e_date desc ) where r_num = 1 ; T_ID E_DOC_LIST ---------- -------------------------------------------------- 100 doc 203/doc 202/doc 201 101 doc 204/doc 203
The r_num = 1 filter is applied quite late. Is there another way to generate the query or even review the tables.
For the sample query: ----------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 6 | 468 | 6 (50)| 00:00:01 | |* 1 | VIEW | | 6 | 468 | 6 (50)| 00:00:01 | |* 2 | WINDOW SORT PUSHED RANK | | 6 | 216 | 6 (50)| 00:00:01 | | 3 | WINDOW SORT | | 6 | 216 | 6 (50)| 00:00:01 | | 4 | NESTED LOOPS | | 6 | 216 | 4 (25)| 00:00:01 | | 5 | MERGE JOIN | | 6 | 198 | 4 (25)| 00:00:01 | | 6 | TABLE ACCESS BY INDEX ROWID| E | 8 | 208 | 2 (0)| 00:00:01 | | 7 | INDEX FULL SCAN | E_PK | 8 | | 1 (0)| 00:00:01 | |* 8 | SORT JOIN | | 6 | 42 | 2 (50)| 00:00:01 | | 9 | INDEX FULL SCAN | K_I1 | 6 | 42 | 1 (0)| 00:00:01 | |* 10 | INDEX UNIQUE SCAN | T_PK | 1 | 3 | 0 (0)| 00:00:01 | ----------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("R_NUM"=1) 2 - filter(ROW_NUMBER() OVER ( PARTITION BY "K"."T_ID" ORDER BY "K"."T_ID",INTERNAL_FUNCTION("E"."E_DATE") DESC )<=1) 8 - access("K"."E_ID"="E"."E_ID") filter("K"."E_ID"="E"."E_ID") 10 - access("K"."T_ID"="T"."T_ID") and for query in production --------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| --------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 3118K| 425M| | 160K (1)| | 1 | VIEW | | 3118K| 425M| | 160K (1)| | 2 | SORT ORDER BY | | 3118K| 163M| 383M| 160K (1)| | 3 | WINDOW SORT PUSHED RANK| | 3118K| 163M| 383M| 160K (1)| | 4 | WINDOW SORT | | 3118K| 163M| 383M| 160K (1)| | 5 | HASH JOIN | | 3118K| 163M| 40M| 33991 (1)| | 6 | TABLE ACCESS FULL | E | 1053K| 28M| | 4244 (1)| | 7 | NESTED LOOPS | | 3118K| 80M| | 21918 (1)| | 8 | TABLE ACCESS FULL | T | 144K| 1829K| | 282 (2)| | 9 | INDEX RANGE SCAN | K_I1 | 22 | 308 | | 1 (0)| ---------------------------------------------------------------------------------------
TimWong765 wrote:
...
Table a contains 200,000 lines. (* this table is truncated and inserted several times a week *)You could be in one of the rare cases where the index should be rebuild, take a look in the following thread:
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:6601312252730 #69571308712887 (search for 'index of Sweeper')
Make sure that you have checked if you are in this case before going for an expensive index rebuild.Nicolas.
-
Need help with the query string manipulation
Hello
With the help of 10.1.0.4.2
Given a table called PREFIX_CODES that contains a column called PREFIX_CODE
with the following data:
PREFIX_CODE - VARCHAR2 (20)
-------------------
AAA
BENAMER
CARTER
and another table called SUBSCRIBERS with a column called SUBSCRIBER_ID
with the following data:
SUBSCRIBER_ID - VARCHAR2 (30)
---------------------
BBBB-123456
AAA-444444
DD-2222222
EEEE-888888
Is there a query that will pull all the SUBSCRIBER_ID that begin with
each of the PREFIX_CODES? The following query is not valid, but it
This will give you an idea of what I'm trying to do:
SELECT SUBSCRIBER_ID
SUBSCRIBERS
WHERE AS SUBSCRIBER_ID (SELECT PREFIX_CODE |) » %'
OF PREFIX_CODES)
Using the data from above, I would like that the query to return:
BBBB-123456
AAA-444444
Thanks for your help!Hello
Welcome to the forum!
You were on the right track. To find if a given subscriber corresponds to any prefix_code, you can do an EXISTS subquery:
SELECT subscriber_id FROM subsribers s WHERE EXISTS ( SELECT NULL FROM prefix_codes WHERE s.subscriber_id LIKE prefix_code || '%' ) ;
This will tell you if at least a prefix code. It won't tell you exactly how many, or what they were.
Your message, I'm guessing that there may be more than one, and you can deduct the subscriber_id itself, then the above query should work for you. -
The default value based on the field from another table to a custom object
I'm trying to set the default value to a field in the custom object to the value of a field of account. I tried the syntax 50 ways different and just don't get the case. The label for the account field displays the form of s/n, the integration of the tag is ltDBA_ACCT and it appears in the fx reports area as Account.Text_22.
The field of custom object that I am triying update is also called s/n, which was originally the required field 'NAME '. The name of the table, account, should it be included? Do I need a function to the field?
I've updated the external ID using the line with syntex < ID > ID (at least higher ID) so I know that it is possible to define a default value, but s / < n >, < ltDBA_ACCT >, 'account '. "" S/n "and so on are simply not working.
If anyone knows how to get into what I would be really grateful for the help.OK, so if you default a field to the value of another object, you must use the JoinFieldValue function. I think you understand that, based on your original post, but I want to be sure you do.
Then this won't work by default if the folder is created from the object that you want to join the because a default works in record creation and the ID must be available so that it works correctly. It will not work if you choose the record of the related object after that registration of the custom object is created. You can set the default after, but that does not meet your requirements.
The syntax of the default are the following: JoinFieldValue (ref_record_type, foreign_key, field_name).
In your case, ref_record_type is '
', foreign_key is [ ] and field_name is ' '. The best way is to determine what is the name of the field to create a new workflow for the account and use the Workflow Rule Condition expression builder to choose your field ("DBA") in the list. The value returned by the expression builder must be placed in the field_name variable in the function JoinFieldValue (minus the parentheses and quotes). Give it a shot and let me know how you do.
Thom -
Help with the query to return the last possible value
Can someone please help me to create a query for the situation below?
Table: TABLEA
Columns:
FACID VARCHAR2 (10),
DEPTID VARCHAR2 (10),
CHARGENUMBER NUMBER (10)
I have the following data:
A, B, 1
A, B, 2
C, D, 3
C, D, 4
I will return the following:
A, B, 2
C, D, 4
In other words, I would return the last possible CHARGENUMBER for FACID and DEPTID.
The table has no index, and it is responsible for a worksheet in that order.
Thank you very much!Hello
If you have a TIMESTAMP column, called entry_dt, you can use a Top - N query like this to find the last x entries.
WITH got_rnum AS ( SELECT my_table.* , RANK () OVER (ORDER BY entry_dt DESC) AS rnum FROM my_table ) SELECT * -- or list all columns except rnum FROM got_rnum WHERE rnum <= x ;
It is very common to have a trigger to ensure that columns like entry_dt are met.
If you have only one statement that inserts with hundreds of lines, they can all have the same entry_dt. (The value of SYSTIMESTAMP is constant throughout a statement, even if it takes a few seconds).
The above query uses RANK, so if you tell him you want the last 10 entries, it can return more than 10, because it includes all lines with exactly the same entry_dt as the 10th. If you want to exactly 10 rows returned, even if there is a tie for 10th place, then use ROW_NUMBER instead of RANK; the rest of the query is the same. -
Hi all
I have the below requirement.
I'm looking for a way to identify products with the exact same specifications.Master table: Product ID Product Name 1 TV 2 Cellphone 3 Laptop 4 DVD Player Details table: Product ID Spec type Spec Detail 1 Color Blue 1 Weight 20 2 Color Blue 2 Weight 20 3 Color Blue 3 Weight 25 4 Color Blue 4 Weight 20 4 Height 10
That is to say, in the example TV and cell phone above has exact specifications.
So the result of the query must be TV and phone cell phone here.
Is it possible to do in a query, or we need a sql block to perform this action.
Any help would be greatly appreciated.
Thank you
AgathyaHi agathya,
We do not know how you want to handle the situation where more than two products have the same specifications, so I extended your sample data slightly to take account of this situation as well:
SQL> create table products (id,name) 2 as 3 select 1, 'TV' from dual union all 4 select 2, 'Cellphone' from dual union all 5 select 3, 'Laptop' from dual union all 6 select 4, 'DVD Player' from dual union all 7 select 5, 'Radio' from dual union all 8 select 6, 'VCR' from dual 9 / Tabel is aangemaakt. SQL> create table product_specifications (product_id,spec_type,spec_detail) 2 as 3 select 1, 'Color' , 'Blue' from dual union all 4 select 1, 'Weight', '20' from dual union all 5 select 2, 'Color' , 'Blue' from dual union all 6 select 2, 'Weight', '20' from dual union all 7 select 3, 'Color' , 'Blue' from dual union all 8 select 3, 'Weight', '25' from dual union all 9 select 4, 'Color' , 'Blue' from dual union all 10 select 4, 'Weight', '20' from dual union all 11 select 4, 'Height', '10' from dual union all 12 select 5, 'Color' , 'Blue' from dual union all 13 select 5, 'Weight', '20' from dual union all 14 select 6, 'Color' , 'Blue' from dual union all 15 select 6, 'Weight', '20' from dual union all 16 select 6, 'Height', '10' from dual 17 / Tabel is aangemaakt. SQL> select p1.name 2 , p2.name 3 from products p1 4 , products p2 5 , product_specifications ps1 6 , product_specifications ps2 7 where p1.id = ps1.product_id 8 and p2.id = ps2.product_id 9 and p1.id < p2.id 10 group by p1.id 11 , p1.name 12 , p2.id 13 , p2.name 14 having sqrt(count(*)) = 15 count(case when ps1.spec_type = ps2.spec_type and ps1.spec_detail = ps2.spec_detail then 1 end) 16 / NAME NAME ---------- ---------- TV Cellphone TV Radio Cellphone Radio DVD Player VCR 4 rijen zijn geselecteerd.
But why devil you or your specifications product model predecessor like that? You are much more complicated that it should be. And the data type of size and weight should be not the same as those of color. But now they are. And how do limit you the allowed values for the colors? Color, weight and size are characteristic of your products so that they should have been modeled like this.
See how easily your questions becomes after remodeling it:
SQL> drop table product_specifications purge 2 / Tabel is verwijderd. SQL> drop table products purge 2 / Tabel is verwijderd. SQL> create table products (id,name,color,weight,height) 2 as 3 select 1, 'TV', 'Blue', 20, null from dual union all 4 select 2, 'Cellphone', 'Blue', 20, null from dual union all 5 select 3, 'Laptop', 'Blue', 25, null from dual union all 6 select 4, 'DVD Player', 'Blue', 20, 10 from dual union all 7 select 5, 'Radio', 'Blue', 20, null from dual union all 8 select 6, 'VCR', 'Blue', 20, 10 from dual 9 / Tabel is aangemaakt. SQL> select * from products 2 / ID NAME COLO WEIGHT HEIGHT ---------- ---------- ---- ---------- ---------- 1 TV Blue 20 2 Cellphone Blue 20 3 Laptop Blue 25 4 DVD Player Blue 20 10 5 Radio Blue 20 6 VCR Blue 20 10 6 rijen zijn geselecteerd. SQL> select p1.name 2 , p2.name 3 from products p1 4 , products p2 5 where p1.id < p2.id 6 and ( p1.color = p2.color or (p1.color is null and p2.color is null)) 7 and ( p1.weight = p2.weight or (p1.weight is null and p2.weight is null)) 8 and ( p1.height = p2.height or (p1.height is null and p2.height is null)) 9 / NAME NAME ---------- ---------- TV Cellphone TV Radio Cellphone Radio DVD Player VCR 4 rijen zijn geselecteerd.
I hope this helps.
Kind regards
Rob. -
Delete rows in a table when the columns from two tables match
Hello
I have following two tables.
===========================================
create the table empbooth as
(
Select 1 empid, 1 double cabin Union all the
Select option 2, Union 1 double all the
Select 3, Union 1 double all the
Select option 4, Union 2 double all the
Select option 5, 2 double
);
create the table attsht as
(
Select 1 empid, 240 reg, 0 unpaid all double union
Select option 2, reg 200, 0 unpaid of all the double union
Select 3, 240 reg, 0 unpaid all double them union
Select 4 480 reg, 0 unpaid all double union
Select 5 240 reg, unpaid double 0
);
=================================================
I want to remove rows from attsht where corresponding booth (which is stored in the empbooth table) is 1.
The condition is 'where attsht.empid = empbooth.empid and empbooth.booth = 1 '.
I use oracle 10g.
Help, please
delete from attsht where a.empid in (select b.empid from empbooth b where b.booth = 1)
or
remove from attsht a
where exists (select null
of empbooth b
where b.booth = 1
and b.empid = a.empid)
Maybe you are looking for
-
In the past, I used to reload a page several times with just one press the F5 key, with pressing long it charge more often, now long or short by pressing the F5 key is sufficient to reload a page or two times
-
Constant need to restart when you use Windows Update
I tried not Microsoft Update, but it's better than Windows Update? I'm setting up of machines and having to restart not less than 5 times after the installation of SP3. Surely, there must be a better way...
-
Unit component the subscriber station
I'm an end user who constantly calls for one of my unit ports (appears on its main extension as a call to voicemail). She takes the call and (of course) get no air circulation. Any ideas? I have over 500 users of the unit and is not the case for ever
-
Platform upgrade and s/w blackBerry OS Smartphones.
Hello Is upgrade to OS dependent on what platform you're on? I'm under platform v 4.2.0.64 2.2.0.37. I'll be able to upgrade to the latest version 4.5? Is there anyway that I can update the software platform? Kind regards AT BB Pearl 8100
-
Hello I use cisco ise and wlc, at the moment I'm not posturing or anything, just the profiling. Looks like it's not able to go beyond of-APPLE device for iphones, and for laptops, it's show unknown. I put all the options with YOU. Is there a special