Join two tables for desired out put
Hello
I have two tables with structures below:
TAB1:
LEAD_NUM (PRIMARY KEY), IMPERATIVE_1, IMPERATIVE_2, IMPERATIVE_3, IMPERATIVE_4
LEAD_NUM | IMPERATIVE_1 | IMPERATIVE_2 | IMPERATIVE_3 | IMPERATIVE_4 |
34HVJ | CXM | NULL VALUE | DGH | KKK |
TAB2:
LEAD_NUM (FOREIGN KEY), ACCOUNT_NAME, FISCAL_YEAR
LEAD_NUM | ACCOUNT_NAME | FISCAL_YEAR |
34HVJ | ATT | 2010 |
34HVJ | ATT | 2011 |
34HVJ | ATT | 2012 |
I need the output in the format below:
ACCOUNT_NAME | LEAD_NUM | FISCAL_YEAR | IMPERATIVES |
ATT | 34HVJ | 2010 | CXM, DGH, KKK |
ATT | 34HVJ | 2011 | CXM, DGH, KKK |
ATT | 34HVJ | 2012 | CXM, DGH, KKK |
Can anyone help me please with the query?
Thanks in advance:
Arpit
create table TAB1
(
Key elementary school/LEAD_NUM varchar2 (100)
IMPERATIVE_1 varchar2 (100),
IMPERATIVE_2 varchar2 (100),
IMPERATIVE_3 varchar2 (100),
IMPERATIVE_4 varchar2 (100)
);
insert into tab1 values ("34HVJ", "CXM", "NULL", "DGH" 'KKK');
create table TAB2
(
LEAD_NUM varchar2 (100),
Account_name varchar2 (100)
NUMBER OF FISCAL_YEAR
);
ALTER TABLE TAB2
ADD CONSTRAINT fk_PerOrders
FOREIGN KEY (LEAD_NUM)
TAB1 (LEAD_NUM) REFERENCES
INSERT INTO VALUES TAB2 ('34HVJ', 'ATT', 2010);
INSERT INTO VALUES TAB2 ('34HVJ', 'ATT', 2011);
SELECT t2.account_name, t2.lead_num, t2.fiscal_year,
RTRIM (TRIM (CASE WHEN t1.imperative_1 IS NULL or t1.imperative_1 = 'NULL' THEN "ELSE t1.imperative_1 |)) ',' END |
CASE WHEN t1.imperative_2 IS NULL or t1.imperative_2 = 'NULL' THEN ' ELSE t1.imperative_2 | ',' END |
CASE WHEN t1.imperative_3 IS NULL or t1.imperative_3 = 'NULL' THEN ' ELSE t1.imperative_3 | ',' END |
CASE WHEN t1.imperative_4 IS NULL or t1.imperative_4 = 'NULL' THEN ' ELSE t1.imperative_4 | (',' END), ',') requirements
OF tab1 t1, t2 tab2
WHERE t1.lead_num = t2.lead_num
ORDER BY t2.fiscal_year
Answer: -.
Tags: Database
Similar Questions
-
By comparing the two tables for the integrity of the data
Hi all
I need to compare two tables for the integrity of the data through the SQL query.If you need to compare all the columns of t1 to t2:
(SELECT * FROM t1 MINUS SELECT * FROM t2) UNION ALL (SELECT * FROM t2 MINUS SELECT * FROM t1);
Kind regards
Ankit Rouault
http://theoraclelog.blogspot.in -
SQL: JOIN two table also corresponding column NULL how?
Hello
I'm trying to join two tables which works fine,
But if there are NULL values, then, JOIN does not.
I have two tables TEMP_DD AND TEMP_EE, in which two line
is the column: allocation A_ID,.
IE: 112 and NULL and I want both my sql output, but how?
I tried under sql as it returns only a single line of 112 and does not return a null row which is a football game.
How to remedy this situation?SELECT * FROM TEMP_DD JOIN TEMP_EE ON (TEMP_DD.A_ID = TEMP_EE.A_ID);
OUTPUTcreate table TEMP_DD ( A_ID VARCHAR2(3), B_ID VARCHAR2(4), C_ID VARCHAR2(10) ); create table TEMP_EE ( A_ID VARCHAR2(3), B_ID VARCHAR2(4), C_ID VARCHAR2(10) ); insert into TEMP_DD (A_ID, B_ID, C_ID) values ('112', '1123', '12345678'); insert into TEMP_DD (A_ID, B_ID, C_ID) values (NULL, '1123', '12345678'); insert into TEMP_DD (A_ID, B_ID, C_ID) values ('212', '1123', '12345678'); insert into TEMP_EE (A_ID, B_ID, C_ID) values ('112', '1123', '12345678'); insert into TEMP_EE (A_ID, B_ID, C_ID) values (NULL, '1123', '12345678'); insert into TEMP_EE (A_ID, B_ID, C_ID) values ('312', '1123', '12345678');
---------
"112', ' 1123," "12345678".
(NULL, ' 1123","12345678 ".Hello
Wrap both sides in an NVL IE. NVL (col1, 'X'), WHERE = NVL(col2,'X').
See you soon
Ben
-
How to join two tables if you transpose the rows, columns and rows in one of the table
Hi guys,.
can someone help me please in the write request
I have two tables
Agents and Agent phones but in the agent phones table for the id of an agent it displays 4 rows because one of the column there types of different phones (office, mobile, home, fax)
So instead of display 4 rows, I used max(case...) to convert rows to columns
now how to reach it with another table
Requirement:
Database: 11.2.0.2.0
create the table AGENT_PHONE
(
agent_id NUMBER (20) not null,
agent_type_code VARCHAR2 (10) not null,
agent_type_prefix VARCHAR2 (10) not null,
Phone_Number VARCHAR2 (16) not null,
phone_type_code VARCHAR2 (10) not null
)
CREATE TABLEAGENTS
(
agent_id NUMBER (20) not null,
agent_type_code VARCHAR2 (10) not null,
agent_type_prefix VARCHAR2 (10) not null,
NAME VARCHAR2 (40) NOT NULL
)
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '4805551436', 'CELL');
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '1111111111', 'PHONE');
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '2223334444',' OFF');
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '5556667788', 'FAX');
INSERT INTO VALUES AGENTS
(29709, ARE ', 'OFFICE', 'FLY');
INSERT INTO VALUES AGENTS
(1234, ARE ', 'OFFICE', 'MIKE');
SELECT * FROM AGENT_PHONES
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX PHONE_NUMBER PHONE_TYPE_CODE ---------------------------------------------------------------------------------------------
29709 RE OFFICE 4805551436 CELL 29709 RE OFFICE 1111111111 PHONE 29709 RE OFFICE 2223334444 OFF 29709 RE OFFICE 5556667788 FAX
SELECT * AGENTS
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME
29709 RE OFFICE ROB 1234 RE OFFICE MIKE
This is so the data we have in both table
Now, I transposed rows to columns in the table of agent phones so I used the following query
SELECT AP. AGENT_ID,. AGENT_TYPE_CODE,. AGENT_TYPE_PREFIX.
MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'CELL' THEN AP. PHONE_NUMBER END) AS CELL.
MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'OFF' THEN AP PHONE_NUMBER END) AS TURNED OFF.
MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'FAX' THEN AP. PHONE_NUMBER END) LIKE FAX,.
MAX (CASE WHEN PHONE_TYPE_CODE = 'PHONE'. THEN AP PHONE_NUMBER END) AS PHONE
AGENT_PHONE AP
WHERE AP. AGENT_ID = 29709
GROUP OF AP. AGENT_ID, AP. AGENT_TYPE_CODE, AP. AGENT_TYPE_PREFIX.
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL OFF FAX PHONE 1 29709 RE OFFICE 4805551436 2223334444 5556667788 1111111111 My question is how this to join the agents table so that my output should be like this...
I want to display all the results in the table of the Agent, even if they are not in the table of agent phones. As you can see there are other agent id 1234 is also populated
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788 1234 RE OFFICE MIKE Currently, I run this query and I get the output as below
SELECT *.
AGENTS HAS
LEFT OUTER JOIN AGENT_PHONE AP
ON A.AGENT_ID = AP. AGENT_ID
AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.
AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX PHONE_NUMBER PHONE_TYPE_CODE 1 29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 CELL 2 29709 RE OFFICE ROB 29709 RE OFFICE 1111111111 PHONE 3 29709 RE OFFICE ROB 29709 RE OFFICE 2223334444 OFF 4 29709 RE OFFICE ROB 29709 RE OFFICE 5556667788 FAX 5 1234 RE OFFICE MIKE I want id 29709 agent in a line with 1234 agent also id to display
You can rotate your phone number of agent in columns
Select *.
of AGENT_PHONE
pivot)
min (PHONE_NUMBER)
for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')
)
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788 Then you can join to view inline or CTE
with AGENT_PHONE_PIVOT like)
Select *.
of AGENT_PHONE
pivot)
min (PHONE_NUMBER)
for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')
)
)
SELECT *.
AGENTS HAS
LEFT OUTER JOIN AGENT_PHONE_PIVOT AP
ON A.AGENT_ID = AP. AGENT_ID
AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.
AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX 29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788 1234 RE OFFICE MIKE - - - - - - - Is that what you're looking for?
-
JOIN the question... Join two tables without omitting lines
I came across a problem that should be an easy fix (I hope), but I'm having a hard time to come up with a solution.
Basically I have two tables, one with the actual amounts with the budget. I have to write a sql statement select that joins these tables together and includes all of their lines. I was able to join the tables by using JOIN, LEFT JOIN and RIGHT JOIN, but it always fails the lines I need.
Below, I have examples of my tables (AMOUNT_TABLE and BUDGET_TABLE). For simplicity, I built the examples to show the same values in the first four columns, with the 5th and 6th columns (SUB_ACCOUNT, AMOUNT, BUDGET) as the only values that are different. My actual tables are not quite that simple, but I don't think it was relavent to this issue.
AMOUNT_TABLE
FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT 2013
1 11111 555555 0000 100 2013 1 11111 555555 1000 100 2013 1 11111 555555 2000 100 2013 1 11111 555555 3000 100 2013 1 11111 555555 4000 100 BUDGET_TABLE
FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT BUDGET 2013
1 11111 555555 3000 200 2013 1 11111 555555 4000 200 2013 1 11111 555555 5000 200 2013 1 11111 555555 6000 200 Here's what I hope. Note that SUB_ACCOUNTs 0000, 1000, and 2000 show without budget amounts since there is not a corresponding line in the BUDGET_TABLE. And same for SUB_ACCOUNTs 5000 and 6000, they show budgets with no amount because there is not a corresponding line in the AMOUNT_TABLE.
(exit)
FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET 2013 1 11111 555555 0000 100 0 2013 1 11111 555555 1000 100 0 2013 1 11111 555555 2000 100 0 2013 1 11111 555555 3000 100 200 2013 1 11111 555555 4000 100 200 2013 1 11111 555555 5000 0 200 2013 1 11111 555555 6000 0 200 If all goes well, my question is clear. Any help on this would be greatly appreciated. Thanks in advance.
Use the join ANSI - FULL OUTER JOIN syntax:
with amount_table like)
Select fiscal_year 2013, 1 period, 11111 acct_unit, 555555, 0000 sub_account, amount 100 of all the double union
Select 2013,1,11111,555555,1000,100 from all the double union
Select 2013,1,11111,555555,2000,100 from all the double union
Select 2013,1,11111,555555,3000,100 from all the double union
Select double 2013,1,11111,555555,4000,100
),
budget_table like)
Select 1 time, 11111 acct_unit, account 555555, sub_account 3000, 2013 fiscal_year, budget of 200 Union double all the
Select 2013,1,11111,555555,4000,200 from all the double union
Select 2013,1,11111,555555,5000,200 from all the double union
Select double 2013,1,11111,555555,6000,200
)
Select nvl (a.fiscal_year, b.fiscal_year) fiscal_year,
period of NVL (a.period, b.period),
NVL (a.acct_unit, b.acct_unit) acct_unit.
account of NVL (a.Account, b.Account),
NVL (a.sub_account, b.sub_account) sub_account.
Amount NVL(a.amount,0),
NVL(b.budget,0) budget
of amount_table one
full join
budget_table b
on)
a.Fiscal_Year = b.fiscal_year
and
a.period = b.period
and
a.acct_unit = b.acct_unit
and
a.Account = b.account
and
a.sub_account = b.sub_account
)
/
FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
----------- ---------- ---------- ---------- ----------- ---------- ----------
2013 1 11111 555555 0 100 0
2013 1 11111 555555 1000 100 0
2013 1 11111 555555 2000 100 0
2013 1 11111 555555 3000 100 200
2013 1 11111 555555 4000 100 200
2013 1 11111 555555 6000 0 200
2013 1 11111 555555 5000 0 2007 selected lines.
SQL >
SY.
-
I had two Tables.APPROVAL_ROUTING_TAB and doc_issue_tab, where APPROVAL_ROUTING_TAB has more lines. I need to make a join of two tables such as all APPROVAL_ROUTING_TAB lines should be displayed (multiple lines) but always connect with the doc_issue_tab. I did an outer join syntax failed.
What is the correct syntax for this.
Key_ref takes the outline "DOC_CLASS = PR_CLASS_1 ^ DOC_NO = 1000007 ^ DOC_REV = A3 ^ DOC_SHEET = 1 ^ '.
SELECT
AR.line_no LINE_NO,
AR.step_no STEP_NO,
AR.lu_name LU_NAME,
AR.key_ref KEY_REF,
AR. Description DESCRIPTION,
di. Status STATUS
From ar APPROVAL_ROUTING_TAB, doc_issue_tab di
WHERE
AR.key_ref = 'DOC_CLASS =' | di. DOC_CLASS |' ^ DOC_NO =' | di.doc_no: ' ^ DOC_REV =' | di.doc_rev: ' ^ DOC_SHEET =' | di.doc_sheet: ' ^') (+)
Thanks in advance
PrashHere is an example:
with t1 as (select 1 id, 'd1=fred^d2=john^d3=bob^' col2 from dual union all select 1 id, 'd1=fred^d2=john^d3=george' col2 from dual), t2 as (select 'fred' d1, 'john' d2, 'bob' d3 from dual union all select 'jim' d1, 'john' d2, 'bob' d3 from dual) select * from t1, t2 where t1.col2 = 'd1='||d1(+)||'^d2='||d2(+)||'^d3='||d3(+)||'^'; ID COL2 D1 D2 D3 ---------- ------------------------- ---- ---- --- 1 d1=fred^d2=john^d3=bob^ fred john bob 1 d1=fred^d2=john^d3=george
-
Hello
I want to join the two tables to retrieve the data from the columns of the two table passing parameters to the join query. Tables have primary and foreign key relationships
Details of the table
Alert-1 - AlertCode (FK), AlerID (PK)
2 AlertCode-AlertDefinition-(PK)
Help, please
----------
Hi Vincent,.
I think that you have not worked on adf 12.1.3. In adf 12.1.3 you don't have to explicitly create the association. When you create the EO to your table, Association xxxxFkAssoc, will be created by ADF12.1.3 for you automatically. Please try this and do not answer anything... You can also follow the links below. I solved the problem by using the following link
---
-
How to join two tables without constraints?
I want to get back the tables to join without constraints!
Table 1:
get 100
101 wet
series 102
and
Table 2:
10 xxx movies
11 yyy
12 zzz
QUERY 1:
SELECT * FROM TO LEAVE P, CUSTES C
WHERE (P.ID, P.NAME, C.ID, C.NAME) IN (SELECT P1.ID, P1.NAME, C1.ID, C1.NAME
OF P1, C1 CUSTES TO GO)
I got the result like this,
ID ID NAME
101 wet 10 xxx
zzz 101 wet 12
YYY 101 wet 11
Get 100 10 xxx
102 the yyy 11 value
series 102 10 xxx
100 get 11 yyy
100 get 12 zzz
102 the value 12 zzz
All ranks was sent three times! but I need to write once.
QUERY 2:
Select id as pid, name as the name of go
Union
Select id as pid, name as the name of custes;
QUERY2 OUTPUT IS.
NAME OF PID
10 xxx movies
11 yyy
12 zzz
get 100
101 wet
series 102
In the 2nd query get the attached files of the two tables. But my need is two tables record to display like this
ID NAME NAME_1 ID_1
Get 10 xxx 100
wet 11 101 yyy
set of 12 zzz 102
I'm looking for is, I want to join in parallel columns in my trips!
Is there a source... ? or the same code is happy...!Something like that?
WITH t1 AS (SELECT '100' id, 'get' name FROM DUAL UNION SELECT '101', 'wet' FROM DUAL UNION SELECT '102', 'set' FROM DUAL), t2 AS (SELECT '10' id, 'xxx' name FROM DUAL UNION SELECT '11', 'yyy' FROM DUAL UNION SELECT '12', 'zzz' FROM DUAL) SELECT id, name, (SELECT id FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in WHERE t_in.rw = t_out.rw) id_1, (SELECT name FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in WHERE t_in.rw = t_out.rw) name_1 FROM (SELECT ID, name, ROWNUM rw FROM t1) t_out
SQL> WITH t1 AS (SELECT '100' id, 'get' name FROM DUAL 2 UNION 3 SELECT '101', 'wet' FROM DUAL 4 UNION 5 SELECT '102', 'set' FROM DUAL), 6 t2 AS (SELECT '10' id, 'xxx' name FROM DUAL 7 UNION 8 SELECT '11', 'yyy' FROM DUAL 9 UNION 10 SELECT '12', 'zzz' FROM DUAL) 11 SELECT id, 12 name, 13 (SELECT id 14 FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in 15 WHERE t_in.rw = t_out.rw) 16 id_1, 17 (SELECT name 18 FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in 19 WHERE t_in.rw = t_out.rw) 20 name_1 21 FROM (SELECT ID, name, ROWNUM rw FROM t1) t_out; ID NAME ID_1 NAME_1 --- --- -- --- 100 get 10 xxx 101 wet 11 yyy 102 set 12 zzz SQL>
The number of rows in the tables are the same?
-
query by default two tables for block
Hello
How can I make defaulet query block of two tables?
I know it's default_query in set_block_property, but there is no clause only 'where' and I put clause of two tables. Is a solution?
concerningYou can use a block of Clause From database. This allows you to base a block on a complex query without having to create a view in the database. Here are the steps:
- Manually create a data block
- Create an item in the block for each column returned by the query - make sure that the data type is correct.
- In the block properties, set the following properties:
- Query data Source type = F R O M Clause query
- Data Source Name = your request
- Mode key = U p d a t a b l e
- Query data Source type = F R O M Clause query
- Manually create a data block
Note: If your query uses summary calculations, make sure you alias the result and ensure that matches alias name of the item in the data of block. It should also be noted that the blocks based on a F r o m query Clause are read-only. If you need be able to update the underlying tables, you can use transactional triggers or the block of data based on a procedure.
For a complete list of this process - Discover My Oracle Support Document ID: * 69884.1 - how to use F rom query Clause in forms *.
Hope this helps,
Craig B-)
If someone useful or appropriate, please mark accordingly.
Published by: Silvere on August 10, 2010 12:37
How to join two tables of different schemas of Oracle by using a subquery
I'm trying to join two different schemas of Oracle tables using a subquery. I can extract data from each of the tables without problem. However, when I combine select statements it by using a subquery I get Oracle error *'ORA-00936: lack of expression ' *. Given that each SELECT statement runs on its own without error I don't understand what's missing. I'm trying to get the result set is matching the LINE_ID of PDTABLE_12_1 in the schema with the table PDTABLE_201 MAT_DESCRIPTION DD_12809 in the RA_12809 schema.The query is as follows:
SQL = "SELECT [DD_12809]. [PDTABLE_12_1]. LINE_ID OF [DD_12809]. [PDTABLE_12_1] JOIN "_".
+ "(SELECT [RA_12809]. [PDTABLE_201]. MAT_DESCRIPTION "_".
"FROM [RA_12809]. [PDTABLE_201]) AS FAB "_".
+ 'ON [DD_12809]. [PDTABLE_12_1]. PIPING_MATER_CLASS = FAB. PIPING_MATER_CLASS ".
The format of the request is copied from a manual of programming SQL.
I also tried running the query uses a right JOIN on the two tables, but got the same results. Any ideas would be useful. Thank you!
Published by: user11338343 on October 19, 2009 06:55
The format for the join of two tables in Oracle feels like any other database:
SELECT a.col1, a.col2, ..., b.col1, b.col2, ...
FROM schema1.table1 a,
JOIN schema2.table2 b ON a.col = b.col and ...
WHERE a.other_col = 'FRED'
AND ....;
Do not place bracketed identifiers in Oracle. The account that connects to the database must have select privileges on the two tables.
Summary
two tables:
Table 1 categories
Table 2A categories that someone has selected
HTML form that updates the user's data:
form should show all the options in the category dynamically in table 1
and also to display the check box of the category as controlled dynamically if the person chose by table 2
The nuts and bolts
Attempt 1
My sql:
SELECT cat.id, cat.category, mcat.category as mcategory
THE CAT of categories, members_categories mcat
WHERE mcat.member_id = ' "." $_GET ['id']. »"
ORDER BY category ASC
(run on its own, all categories of table 1 are shown twice and the results of table 2 is a total cluster.)
area of the form with checkboxes:
<? PHP {? >}
< input <? PHP if (!) ((strcmp($row_rsCategories['mcategory'],$row_rsCategories['id'])))) {echo ' checked =------'checked\' ' ;}?} > name = "category []" type = "checkbox" value = "<?" PHP echo $row_rsCategories ['id'];? ">" / > <? PHP echo $row_rsCategories ['category'];? > < br / >
<? PHP} while ($row_rsCategories = mysql_fetch_assoc ($rsCategories));? >
what I have here results:
all categories displayed twice with selected categories of table 2 verified = by the results of sql when running alone
Attempt 2
My sql:
SELECT cat.id, cat.category, mcat.category as mcategory
CAT categories
LEFT JOIN members_categories mcat WE mcat.category = cat.id
WHERE mcat.member_id = ' "." $_GET ['id']. »"
ORDER BY category ASC
(run on its own, all categories of table 1 who have a match in the table 2 and none of the other in table 1 shows)
area of the form with checkboxes:
even the first attempt
what I have here results:
all categories selected in table 2 shows and checked, and no other choices of table 1 = by the results of sql when running alone
Attempt 3
My sql:
SELECT cat.id, cat.category, mcat.category as mcategory
THE CAT of categories, members_categories mcat
WHERE mcat.member_id = ' "." $_GET ['id']. »"
GROUP BY cat.id
ORDER BY category ASC
(running his own, all the choices in the category of table 1 are displayed, however, the mcategory column displays the lowest category numbered (same one) against all of these options rather then correspond to their.)
area of the form with checkboxes:
even the first attempt
what I have here results:
all choice of category in table 1 are displayed, however, only the first category in table 2 (which in this case is the lowest number) is marked as checked with the checkboxe, even if there is more then one category in table 2 = by the results of sql when running alone
so, can anyone help? I'm just banging my head against the wall here is something missing that should be obvious, because the sql is not giving me what I need to work with the form in a loop region. Perhaps another approach should be taken and I have change the loop as well, but I think that this can be resolved with the sql. Thanks in advance.
Well, you can use two separate sql queries...
one with the names of the categories
and the second nested with the loop that references the id of category in table 1 to pair with table 2
How can I join two tables that belong to two different databases?
I can build a SQL query in SQL Server Management Studio, which performs a join of a table in a database with a table in another database. I have a good 'read' name to username/password for the two databases.
How to do the join in ColdFusion? The tag < cfquery > requires a unique data source. I could do like two queries and through comparing, or maybe even some use dbtype = query, but it would be horribly less effective than a direct join.
I could place the SQL statement in a stored procedure, but that seems like overkill - all the necessary number of fields in the "WHERE" clause will change based on the logic of the ColdFusion program.
Does anyone know of a way to do this with < cfquery >?
How do you take in SQL Server Management Studio? You must do something that I'm not aware, if what you're doing here does not work in a
The way I did in the past is just to fully qualify the names of the tables. Server.databaseOwner.database.table know if I remember correctly. This does not require that the database connected to the name of data source is configured to be allowed to connect to the database.
Natural join of Table to herself out of Cartesian product
Hello
With
CREATE TABLE A)
an INTEGER,
b VARCHAR (15).
c DATE
);
INSERT IN A (a, b, c) VALUES (1, 'AAA', SYSDATE);
INSERT IN A (a, b, c) VALUES (2, 'BBBB', SYSDATE);
INSERT IN A (a, b, c) VALUES (3, 'CCCCC', SYSDATE);
CREATE VIEW A1
AS SELECT * FROM A
;
the query
SELECT
*
A.
NATURAL JOIN HAS
;
returning nine records - but
SELECT
*
A.
NATURAL JOIN A1
;
only three - which is what I expected.
Why the difference?
Tested in 11g. Where is the documentation pertaining to this particular aspect?
Thank you!
Report it as a bug, the correct result, it's the three ranks of result you can go back to giving has an alias, for example:
SQL > select * a natural join a and b;
A B C
---------- --------------- ---------
1 AAA 15 JULY 15
2 BBBB 15 JULY 15
3 CARTER 15 JULY 15
3 selected lines.
SQL > select * from a natural join.
A B C
---------- --------------- ---------
1 AAA 15 JULY 15
1 AAA 15 JULY 15
1 AAA 15 JULY 15
2 BBBB 15 JULY 15
2 BBBB 15 JULY 15
2 BBBB 15 JULY 15
3 CARTER 15 JULY 15
3 CARTER 15 JULY 15
3 CARTER 15 JULY 15
9 selected lines.
Run on 11.2.0.4 - but reproduced on 12.1.0.2
Concerning
Jonathan Lewis
unfavourable update when joining two tables
HelloORACLE VERSION
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
"CORE 11.1.0.7.0 Production"
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
create the table and anonymous blocks to insert data into tablescreate table TAB_ONE(LOC_ID NUMBER,OPENDATE VARCHAR2(30),CLOSEDATE VARCHAR2(30));
create table TAB_TWO(ID NUMBER,LOC_ID VARCHAR2(30),INSERTDATE VARCHAR2(30));
DECLARE
BEGIN
FOR I IN 1 .. 10 LOOP
INSERT INTO TAB_ONE VALUES(i,trunc(sysdate),NULL);
INSERT INTO TAB_ONE VALUES(i+1,NULL,NULL);
INSERT INTO TAB_ONE VALUES(i+2,NULL,NULL);
END LOOP;
COMMIT;
END;
select * from TAB_ONE;
DECLARE
BEGIN
FOR I IN 1..10 LOOP
INSERT INTO TAB_TWO values(i,i+1,trunc(sysdate));
END LOOP;
COMMIT;
END;
select * from TAB_TWO;
Here, I want to update the TAB_ONE table where opendate is null with the insertdate of TAB_TWO;join on LOC_ID condition.
I tried this so far... but get SQL error: ORA-01427: einreihig subquery returns multiple rows
01427 00000 - "einreihig subquery returns several lines.
update TAB_ONE SET OPENDATE=(select INSERTDATE from TAB_TWO T2,TAB_ONE T1 where T2.LOC_ID=T1.LOC_ID and T1.OPENDATE is NULL)
where exists (select 1 from TAB_TWO T2,TAB_ONE T1 where T2.LOC_ID=T1.LOC_ID and T1.OPENDATE is NULL) and OPENDATE is NULL;
could someone give me suggestion to acheieve this?Thank you
Mike
SQL> update TAB_ONE T1
2 SET OPENDATE=(select INSERTDATE from TAB_TWO T2 where T2.LOC_ID=T1.LOC_ID)
3 where T1.OPENDATE is NULL;
20 rows updated.
SQL> select * from TAB_ONE;
LOC_ID OPENDATE CLOSEDATE
---------- ------------------------------ ------------------------------
1 15-JUN-11
2 15-JUN-11
3 15-JUN-11
2 15-JUN-11
3 15-JUN-11
4 15-JUN-11
3 15-JUN-11
4 15-JUN-11
5 15-JUN-11
4 15-JUN-11
5 15-JUN-11
6 15-JUN-11
5 15-JUN-11
6 15-JUN-11
7 15-JUN-11
6 15-JUN-11
7 15-JUN-11
8 15-JUN-11
7 15-JUN-11
8 15-JUN-11
9 15-JUN-11
8 15-JUN-11
9 15-JUN-11
10 15-JUN-11
9 15-JUN-11
10 15-JUN-11
11 15-JUN-11
10 15-JUN-11
11 15-JUN-11
12
30 rows selected.
Max
Problem of ORA-00918 join of tables for the update
HelloI have 2 tables: PAR_SPEC_OPS and T_PAR and I'm trying to update the 2 columns with values from the second table in the first.
Here is my script:
Update
(
Select membership_id, membership_status
Of Par_Spec_Ops P, T_Par T
Where P.Tracking_ID = T.Tracking_ID
)
Set P.membership_id = T.membership_id,
P.membership_status = T.membership_status;
Running this gives me ORA-00918: column ambiguously defined. I watched this and it is said that happens when there is a common column in tables 2 and I'm not using prefixes, but as you can see on my order, I'am using prefixes. I tried with and without alias, but I get the same error.
You guys have any ideas?
Thank you and best regards,
Ionut
Published by: 837311 November 8, 2011 04:24
Select membership_id, membership_status
Columns of the table P or T? Oracle does not know...
Maybe you are looking for
-
Funky problem continuously with a specific application
This problem could be related to how this app was designed, but I thought someone here might know a hardware fix. Streaming of any application to airports is easy-peasy, but this particular application of the Apple TV streaming is a real struggle - b
-
left click in the web browser options are disabled in the latest version
In all previous versions of firefox, I had no problem in the drop-down list when a left click to open a link in a new tab or save the highlighted text or even to save an image on my disk. But now with the last update (20.0.1) I came across something
-
After the Service Pack 1 update my windows is more authentic.
Hello again, New but problem! 3 days on the line with all the new updates as SP1 Inc. installed, I have a command prompt to run the tool Validation of Windows. Doing it now says my OS as 'not true' (Build 7601). I used the product key of my OEM (HP)
-
HDX 16: Blu - ray is stopped playing HDCP compatible TV as monitor extended
Have a new TV Vizio, which is certainly HDCP, I use my HP HDX 16 as a blu - ray player for. I played a Blu - ray disc very well two weeks ago. In the meantime, I detached from the laptop and connected to a compatible monitor non HDCP for some basic
-
Create a ticker of news style to 14 items?
In iMovie, I can add a 'news ticker' power that scrolls along the bottom of the screen during a video.I saw a video of youtube for Premier Pro describing making the start and end points "off screen" to create this effect - but I can't find it in elem