JOIN clause in SQL
Hi there,
I have got a quick question to ask:
Can INNER JOIN be written with just the keyword JOIN?
For example,
INNER JOIN table_b b ON a.col = b.col
OR
JOIN table_b b ON a.col = b.col
Thanks
yes it is JOIN table_b b ON a.col = b.col or INNER JOIN table_b b ON a.col = b.col
Edited by: orant575 on Jun 28, 2009 1:27 PM
Similar Messages
-
ANSI SQL Syntax - What belongs to join-clause and what to where-clause
Hello,
we currently have a discussion about the ANSI SQL Syntax where we do not agree what belongs to the join clause and what belongs to the where clause in an ANSI Sytnax SQL Query.
Lets say there is a query like this:
+SELECT *+
FROM employees emp, departments dept
WHERE emp.dept_country = dept.dept_country
AND emp.dept_name = dept.dept_name
AND dept.dept_type = 'HQ'
AND emp.emp_lastname = 'Smith'
Primary key of the departments table is on the columns dept_country, dept_name and dept_type. We have a Oracle database 10g.
Now I have rewritten the query to Ansi Syntax:
+SELECT *+
FROM employees emp
JOIN departments dept
ON emp.dept_country = dept.dept_country AND emp.dept_name = dept.dept_name
WHERE dept.dept_type = 'HQ'
AND emp.emp_lastname = 'Smith'
Another developer says that this is not completely correct, every filter on a column that belongs to the primary-key of the joined table has to be in the join clause, like this:
+SELECT *+
FROM employees emp
JOIN departments dept
+ON emp.dept_country = dept.dept_country AND emp.dept_name = dept.dept_name AND dept.dept_type = 'HQ'
WHERE emp.emp_lastname = 'Smith'
Can somebody tell me which on is correct?
Is there any definition for that? I couldn't find it in the Oracle Database definition.
I just found out the names of the ANSI documents here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_standard_sql001.htm#i11939
I had a look at the ANSI webstore but there you have to buy the PDF files. In my case thats exaggerated because both of the Queries work and i am just interessted if there is one correct way.
Thank you in advance
MarcoHi,
As i guideline i would say, answer the question: should the result of the join be filtered or should only filtered rows be joined from a particular table?
This is helpful in the case of outer joins also, for inner joins it doesnt matters as said already be former posters, where there may be hughe semantical differences depending of where the predicates are placed.
From performance view, if we talk about oracle, take a look a the execution plans. You will see that there is (probably) no difference in case of inner joins. Even in case of outer joins the optimizer pushes the predicate as a filter towards the table if it semantically possible.
Regards -
Is it possible to pass a variable in FROM clause in SQL?
Hi Experts,
<i><b>loop at it_db_table.
select field1 from it_db_table-table_name into my_it.
endloop.</b></i>
I mean, Is it pass a variable value to FROM clause in SQL?
I got the info from SAP as,
<i><b>Works like variants 1-3, provided the source_text varialb contains the table name or a join expression as ABAP source text.
Examples
Output of a list of all customers:
DATA tabname(10).
DATA: BEGIN OF wa,
id TYPE scustom-id,
name TYPE scustom-name,
END OF wa.
tabname = 'SCUSTOM'.
SELECT id name INTO CORRESPONDING FIELDS OF wa FROM (tabname).
WRITE: / wa-id, wa-name.
ENDSELECT.</b></i>
thanq.Here is a short sample of a dynamic select statement.
Enter your table name in the parameter on selection screen. Enter you where clause in the select-option on selection screen.
I used.....
MARA
MTART = 'HALB'
report zrich_0004 .
data: xwhere(30) type c.
data: iwhere(30) type c occurs 0.
data:itab(1000) type c occurs 0 with header line.
parameters: p_table(30) type c.
select-options: s_where for xwhere.
loop at s_where.
clear iwhere.
xwhere = s_where-low.
append xwhere to iwhere.
endloop.
select * up to 100 rows into table itab
from (p_table)
where (iwhere).
loop at itab.
write:/ itab.
endloop.
Regards
vasu -
Converting oracle join to Ansi sql join
Hi Guys,
I am new to SQL and trying to convert the following Oracle query (joins) into ANSI sql joins...Can someone please help me?
SELECT M.EXTERNALCODE, M.NAME AS MNAME, SC.BIRIM, SM.TRANSACTIONDATE, SMD.AMOUNT,
SMD.UNITPRICE, SM.ID AS SMID, SMD.ID AS SMDID, F.NAME AS FNAME,
IFNULL (SMD.AMOUNT, 0, SMD.AMOUNT) * IFNULL (SMD.UNITPRICE, 0, SMD.UNITPRICE) AS TOTALPRICE, SMD.AMOUNT AS RECEIVED_QUANTITY,
PD.ORDERID, PD.AMOUNT QUANTITY, PO.PROCESSDATE
FROM STOCKMAINTRANSACTION SM,
STOCKMAINTRANSACTIONDETAIL SMD,
MATERIAL M,
STOCKCARD SC,
FVSTOCK FVS,
FIRM F,
PURCHASEORDER PO,
PURCHASEORDERDETAIL PD,
PURCHASEORDERDETAILSUPPLIED PDS
WHERE SM.ID = SMD.MAINTRANSACTIONID
AND SMD.MATERIALID = M.ID
AND SMD.STOCKCARDID = SC.ID
AND SM.PROPREF = FVS.RECORDID(+)
AND FVS.FIELDID(+) = 2559
AND FVS.FLEVEL(+) = 'F'
AND F.ID(+) = SUBSTR (FVS.FVALUE, 1, 9)
AND SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)
AND SMD.CANCELLED = 0
AND SMD.STOCKUPDATED = 1
AND SMD.ID = PDS.STOCKMAINTRANSACTIONDETAILID
AND PDS.ORDERDETAILID = PD.ORDERDETAILID
AND PO.ORDERID = PD.ORDERID
AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}
ORDER BY F.NAME, M.EXTERNALCODE, SM.TRANSACTIONDATE
Really appreciate the help!
Thanks.Hi,
Welcome to the forum!
To convert to ANSI syntax, replace join conditions in the WHERE clause
FROM x
, y
WHERE x.x1 = y.y1
AND x.x2 = y.y2with ON conditions in the FROM clause:
FROM x
JOIN y ON x.x1 = y.y1
AND x.x2 = y.y2In inner joins, conditions that do not reference 2 tables are not really join conditions, so it doesn't matter if they are in the FROM clause or in the WHERE clause.
In your case
SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)could be part of a join condition involving sm, or it could be in the WHERE clause. Most people find it clearer if 1-table conditions like this are in the WHERE clause.
Again, this only applies to inner joins. For outer joins, all conditions that apply to a table that may lack matching rows must be included in the FROM clause, like this:
LEFT OUTER JOIN fvstock fvs ON sm.propref = fvs.recordid
AND fvs.fieldid = 2559
AND fvs.flevel = 'F'Try it.
If you have trouble, post your best attempt, along with CREATE TABLE and INSERT statements for a little sample data from all the tables involved, and the results you want from that data. Simplify the problem. Post only the tables and columns that you don't know how to handle.
See the forum FAQ {message:id=9360002}
user8428528 wrote:
AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}This is not valid Oracle SQL. Is {@MATERIALID@} some kind of variable? -
With clause in SQL query data model
Hello!
isn't it possible to use the with clause in sql query data models?
for example following query:
WITH
a_test as (
select dummy from dual
select *
from a_test
brings up a "XML Parsing Error: no element found"-error...
BR PaulI tried a slightly different query (see below) and the query worked fine and retrieved data.. I did not get any errors.
WITH
a_test as (
select 'dummy' from dual
select *
from a_test
This works as well.. retrieving the value of the parameter
WITH
a_test as (
select :Test_ID from dual
select *
from a_test
thanks,
BIPuser -
How to use bind variables using in clause in SQL
Hi
Can any one help me in regards Bind variables usage using in clause in sql for String data?
thansAre you looking for a dynamic IN list? As in something like this:
SELECT ... FROM .. WHERE some_col IN (<dynamic list of stuff that is always changing>)If so check this out:
[ How can I do a variable IN list?|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425] -
hi,
i am facing a problem during when clause in sql loader
here is my control file
options(direct=true)
load data
infile 'data_file.txt'
truncate
into table "TABLE_NAME"
when col1 = '1'
trailing nullcols
col1 integer external TERMINATED BY ',',
col2 integer external )
into table "TABLE_NAME"
when col1 = '2'
trailing nullcols
col1 integer external TERMINATED BY ',' ,
col2 integer external )
=======================================
this file loads only data when col1=1 and does not load data when col1=2
can any body help me
thanks in advanceHi,
I currently have the same problem. Seems that SQLLDR WHEN clause only apply for columns that based on datafile. Also, data that to be compared in WHEN clause is get from datafile and you can not make any modification on that data.
How did you do to work around with that? -
SQL JOIN with BPM sql component
Hello friends.
How to use SQL JOIN with BPM sql component?
The tables objects are created but the joined tables belong to different sql components .
I tried something like that, but a error "table doesn't exist" occours.
Ex:
for each element in
SELECT imuImovelCd
FROM IMOVEIS_URBANOS,
Integracao.FGLP.IMOVEIS_PRE_EDITAIS
WHERE IMOVEIS_URBANOS.imuImovelCd = Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipeImuCd
AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedNr = 1
AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedAa = 2008
do
extend this.imoveis using cdImovel = element.imuimovelcd,
nrImovel = call(DEC_ENDERECO, codimovel : element.imuimovelcd, tipoimovel : 1)
end
Edited by: user9008295 on 26/01/2010 05:19ok, ok you are right.
When I try use SQL Statement to make a JOIN with 2 tables on different sql objects, BPM returns "table dosn't exists".
So.... I change my code. I dont know if this is the best way to do, but... i hope u, or everyone, can help me to do a best work.
This code works fine.
for each element in
SELECT ipeImuCd
FROM Integracao.FGLP.IMOVEIS_PRE_EDITAIS
WHERE Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedNr = 1
AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedAa = 2008
do
for each element2 in
SELECT imuImovelDv
FROM IMOVEIS_URBANOS
WHERE imuImovelCd = element.ipeImuCd
do
extend this.imoveis using cdDvImovel = String(element2.imuImovelDv),
cdImovel = Decimal(element.ipeImuCd),
endereco = call(DEC_ENDERECO, codimovel : element.ipeImuCd, tipoimovel : 1)
end
end
Thx a lot!!! -
How can i improve on this join clause
I have a table like this
desc work_table2
WORK_TABLE2_ID NOT NULL NUMBER
APPLICATION_ID NUMBER
APPLICATION_VERSION NUMBER
JOB_ID NUMBER
CUSTOMER_ID NUMBER
ATTRIBUTE_ID NUMBER
TEMPLATE_ID NUMBER
DISTRICT_ID NUMBER
SCHOOL_OID VARCHAR2(32)
PERSON_OID VARCHAR2(32)
CREATE_DATETIME DATE
SCHEMA_NAME VARCHAR2(32)
TABLE_NAME VARCHAR2(32)
COLUMN_NAME VARCHAR2(32)
ROW_ID NUMBER
VALUE VARCHAR2(100)
ACTION VARCHAR2(15)
CIA_VERSION NOT NULL NUMBER
SUB_ROW_ID NUMBER(9)
This is table from which I will be inserting data into other tables. Some sort of standby data table.
Data in this table comes in column format which i
convert into a row. i.e for 1 row in the target table comprises of 10 columns
then i get 10 different rows for that in work_table2
The important columns here are table_name, column_name, value which gives me
the table in which i have to insert the values, the columns of the table & the required values.
I create views out of this table so i can directly insert into the destination tables from
the views. The tables to insert into reside in another schema.
Apart from these columns I also require the job_id, customer_id, action column
which are part of the tables i am going to insert into but will not come from the
column_name column of the work_table2 but do come as separate columns in work_table2
For every row to be inserted into the table i take row_id as the separator and
use it in my join clause
In some cases i get the same row_id for two different rows so i use sub_row_id to get individual rows.
In some cases it is quite possible that i may not get data for few of the columns of the target table. In that case I have I have to show null values in the empty columns
Here is the query i use to create the view. Actually i have created a view generator
PLSQL code which automatically creates views for all the tables.
Though this query gives me the desired output I am very scared looking at the join clause
Could you suggest a better way to get the output
CREATE OR REPLACE VIEW CDL_BELLPERIODMASTER
( OID, CUSTOMER_ID, ORGUNIT_OID, BELLPERIODSET_OID, PERIOD_NUMBER,
SHORT_LABEL, NAME, DESCRIPTION, BEGIN_TIME,
END_TIME, CREATEDBY_OID, CREATEDATE, UPDATEDATE,
ORIGINTYPECD_OID, OWNER_ORGUNIT_OID, CREATE_BY, UPDATE_BY,
UPDATE_DATE, YEAR_TAGGED, APPLICATION_VERSION, INACTIVESTATUS,
ISDELETED, JOB_ID, ACTION )
AS
SELECT OID.value,CUSTOMER_ID.value,ORGUNIT_OID.value,BELLPERIODSET_OID.value,
PERIOD_NUMBER.value,SHORT_LABEL.value,NAME.value,DESCRIPTION.value,
BEGIN_TIME.value,END_TIME.value,CREATEDBY_OID.value,CREATEDATE.value,
UPDATEDATE.value,ORIGINTYPECD_OID.value,OWNER_ORGUNIT_OID.value,
CREATE_BY.value,UPDATE_BY.value,UPDATE_DATE.value,
YEAR_TAGGED.value,APPLICATION_VERSION.value,INACTIVESTATUS.value,
ISDELETED.value,jobs.job_id, act. action
FROM
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='OID') OID,
(SELECT TO_NUMBER(VALUE) value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='CUSTOMER_ID') CUSTOMER_ID,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='ORGUNIT_OID') ORGUNIT_OID,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='BELLPERIODSET_OID')
BELLPERIODSET_OID,
(SELECT TO_NUMBER(VALUE) value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='PERIOD_NUMBER')
PERIOD_NUMBER,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2 WHERE
table_name='WSF_BELLPERIODMASTER' and column_name ='SHORT_LABEL') SHORT_LABEL,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2 WHERE
table_name='WSF_BELLPERIODMASTER' and column_name ='NAME') NAME,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='DESCRIPTION') DESCRIPTION,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='BEGIN_TIME') BEGIN_TIME,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='END_TIME') END_TIME,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2 WHERE
table_name='WSF_BELLPERIODMASTER' and column_name ='CREATEDBY_OID') CREATEDBY_OID,
(SELECT TO_DATE(VALUE,'DD-MON-RRRR') value , row_id, job_id, sub_row_id
FROM work_table2 WHERE table_name='WSF_BELLPERIODMASTER' and
column_name ='CREATEDATE') CREATEDATE,
(SELECT TO_DATE(VALUE,'DD-MON-RRRR') value , row_id, job_id, sub_row_id
FROM work_table2 WHERE table_name='WSF_BELLPERIODMASTER'
and column_name ='UPDATEDATE') UPDATEDATE,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2 WHERE
table_name='WSF_BELLPERIODMASTER' and column_name ='ORIGINTYPECD_OID')
ORIGINTYPECD_OID,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='OWNER_ORGUNIT_OID')
OWNER_ORGUNIT_OID,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2 WHERE
table_name='WSF_BELLPERIODMASTER' and column_name ='CREATE_BY') CREATE_BY,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='UPDATE_BY') UPDATE_BY,
(SELECT TO_DATE(VALUE,'DD-MON-RRRR') value , row_id, job_id, sub_row_id
FROM work_table2 WHERE table_name='WSF_BELLPERIODMASTER' and
column_name ='UPDATE_DATE') UPDATE_DATE,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='YEAR_TAGGED') YEAR_TAGGED,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='APPLICATION_VERSION')
APPLICATION_VERSION,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='INACTIVESTATUS')
INACTIVESTATUS,
(SELECT value , row_id, job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' and column_name ='ISDELETED') ISDELETED,
(SELECT decode(upper(ACTION),'W','U',ACTION) action ,row_id, job_id, sub_row_id
FROM work_table2 WHERE table_name='WSF_BELLPERIODMASTER' AND column_name='OID' ) ACT,
(SELECT row_id , job_id, sub_row_id FROM work_table2
WHERE table_name='WSF_BELLPERIODMASTER' AND column_name='OID' ) JOBS
where
OID.job_id=CUSTOMER_ID.job_id(+) and
OID.job_id=ORGUNIT_OID.job_id(+) and
OID.job_id=BELLPERIODSET_OID.job_id(+) and
OID.job_id=PERIOD_NUMBER.job_id(+) and
OID.job_id=SHORT_LABEL.job_id(+) and
OID.job_id=NAME.job_id(+) and
OID.job_id=DESCRIPTION.job_id(+) and
OID.job_id=BEGIN_TIME.job_id(+) and
OID.job_id=END_TIME.job_id(+) and
OID.job_id=CREATEDBY_OID.job_id(+) and
OID.job_id=CREATEDATE.job_id(+) and
OID.job_id=UPDATEDATE.job_id(+) and
OID.job_id=ORIGINTYPECD_OID.job_id(+) and
OID.job_id=OWNER_ORGUNIT_OID.job_id(+) and
OID.job_id=CREATE_BY.job_id(+) and
OID.job_id=UPDATE_BY.job_id(+) and
OID.job_id=UPDATE_DATE.job_id(+) and
OID.job_id=YEAR_TAGGED.job_id(+) and
OID.job_id=APPLICATION_VERSION.job_id(+) and
OID.job_id=INACTIVESTATUS.job_id(+) and
OID.job_id=ISDELETED.job_id(+) and
OID.job_id= ACT.job_id(+) and
OID.job_id = JOBS.job_id(+) and
OID.row_id=CUSTOMER_ID.row_id(+) and
OID.row_id=ORGUNIT_OID.row_id(+) and
OID.row_id=BELLPERIODSET_OID.row_id(+) and
OID.row_id=PERIOD_NUMBER.row_id(+) and
OID.row_id=SHORT_LABEL.row_id(+) and
OID.row_id=NAME.row_id(+) and
OID.row_id=DESCRIPTION.row_id(+) and
OID.row_id=BEGIN_TIME.row_id(+) and
OID.row_id=END_TIME.row_id(+) and
OID.row_id=CREATEDBY_OID.row_id(+) and
OID.row_id=CREATEDATE.row_id(+) and
OID.row_id=UPDATEDATE.row_id(+) and
OID.row_id=ORIGINTYPECD_OID.row_id(+) and
OID.row_id=OWNER_ORGUNIT_OID.row_id(+) and
OID.row_id=CREATE_BY.row_id(+) and
OID.row_id=UPDATE_BY.row_id(+) and
OID.row_id=UPDATE_DATE.row_id(+) and
OID.row_id=YEAR_TAGGED.row_id(+) and
OID.row_id=APPLICATION_VERSION.row_id(+) and
OID.row_id=INACTIVESTATUS.row_id(+) and
OID.row_id=ISDELETED.row_id(+) and
OID.row_id= ACT.row_id(+) and
OID.row_id = JOBS.row_id(+) and
OID.sub_row_id=CUSTOMER_ID.sub_row_id(+) and
OID.sub_row_id=ORGUNIT_OID.sub_row_id(+) and
OID.sub_row_id=BELLPERIODSET_OID.sub_row_id(+) and
OID.sub_row_id=PERIOD_NUMBER.sub_row_id(+) and
OID.sub_row_id=SHORT_LABEL.sub_row_id(+) and
OID.sub_row_id=NAME.sub_row_id(+) and
OID.sub_row_id=DESCRIPTION.sub_row_id(+) and
OID.sub_row_id=BEGIN_TIME.sub_row_id(+) and
OID.sub_row_id=END_TIME.sub_row_id(+) and
OID.sub_row_id=CREATEDBY_OID.sub_row_id(+) and
OID.sub_row_id=CREATEDATE.sub_row_id(+) and
OID.sub_row_id=UPDATEDATE.sub_row_id(+) and
OID.sub_row_id=ORIGINTYPECD_OID.sub_row_id(+) and
OID.sub_row_id=OWNER_ORGUNIT_OID.sub_row_id(+) and
OID.sub_row_id=CREATE_BY.sub_row_id(+) and
OID.sub_row_id=UPDATE_BY.sub_row_id(+) and
OID.sub_row_id=UPDATE_DATE.sub_row_id(+) and
OID.sub_row_id=YEAR_TAGGED.sub_row_id(+) and
OID.sub_row_id=APPLICATION_VERSION.sub_row_id(+) and
OID.sub_row_id=INACTIVESTATUS.sub_row_id(+) and
OID.sub_row_id=ISDELETED.sub_row_id(+) and
OID.sub_row_id= ACT.sub_row_id(+) and
OID.sub_row_id = JOBS.sub_row_id(+)
RgrdsTry to use this sample.
create or replace view v
as
select dept.deptno deptcode, dept.dname deptname, sal amount
from emp, dept
where emp.deptno = dept.deptno
select decode( grouping(rownum), 1, to_number(NULL), deptcode ) deptcode,
deptname || decode( grouping(rownum), 1, ' total amount' ) deptname,
sum(amount),
grouping(deptcode) g1, grouping(deptname) g2, grouping(rownum)
from v
group by rollup(deptcode,deptname,rownum)
having (grouping(deptcode) = 0 and
grouping(deptname) = 0 and
grouping(rownum)=0)
OR (grouping(deptcode) = 0 and
grouping(deptname) = 0 and
grouping(rownum)=1) -
How to join two pl/sql tables .,.,,Urgent pls help
Hi,
Please tell me how to join to pl/sql tables with example
thanks
aspIf your main intention is to get the common records/or getting whole records from the 2 different pl/sql arrays then , pls check this piece of code & explanation
The SQL language has long offered the ability to apply set operations (UNION, INTERSECT, and MINUS) to the result sets of queries. In Oracle Database 10g, you can now use those same high-level, very powerful operators against nested tables (and only nested tables) in your PL/SQL programs and on nested tables declared as columns inside relational tables.
Let's take a look at some of the syntax needed to do this, starting with UNION.
First, I create a schema-level nested table type:
CREATE OR REPLACE TYPE strings_nt
IS TABLE OF VARCHAR2(100);
Then I define a package and within it create and populate two nested tables of this type, each containing some of my father's and my favorite things:
CREATE OR REPLACE PACKAGE favorites_pkg
IS
my_favorites strings_nt
:= strings_nt ('CHOCOLATE'
, 'BRUSSEL SPROUTS'
, 'SPIDER ROLL'
dad_favorites strings_nt
:= strings_nt ('PICKLED HERRING
, 'POTATOES'
, 'PASTRAMI'
, 'CHOCOLATE'
PROCEDURE show_favorites (
title_in IN VARCHAR2
, favs_in IN strings_nt
END;
In this package, I also include a procedure to show the contents of a strings_nt nested table. This will come in very handy shortly.
By defining these collections in a package, outside any program, they persist (they maintain their state and values) for the duration of my session or until I change or delete them. This means that I can now write programs outside the package to manipulate the contents of those collections.
Note that this package has been simplified for the purposes of presenting collection functionality. In a production application, you should always take care to "hide" your package data, as with these collections, in the package body, and then provide procedures and functions to manage the data.
Suppose, for example, that I would like to combine these two collections into a single collection of our favorites. Prior to Oracle Database 10g, I would have to write a loop that transfers the contents of one collection to another. Now, I can rely on the MULTISET UNION operator, as shown below:
DECLARE
our_favorites
strings_nt := strings_nt ();
BEGIN
our_favorites :=
favorites_pkg.my_favorites
MULTISET UNION ---- Use INTERSECT , if you want to know common records
favorites_pkg.dad_favorites;
favorites_pkg.show_favorites (
'ME then DAD', our_favorites);
END;
The output from this script is:
ME then DAD
1 = CHOCOLATE
2 = BRUSSEL SPROUTS
3 = SPIDER ROLL
4 = PICKLED HERRING
5 = POTATOES
6 = PASTRAMI
7 = CHOCOLATE
------------------------------ -
We want to make an edit in which users will be able to write SQL queries and show them the result in a table. The problem is that, when doing joins, the fields with the same name in both database tables are misinterpreted, for example:
if we have x.name and y.name as columns of two tables (x and y), when we use getString("name") we lose the string for the second getString.
We have tried too:
getString(rsmd.getTableName(i)+".name") being rsmd a ResultSetMetaData object and i the number of the column. It wasn't successful because getTableName didn't return the table name (as we know, it returns the table name or "" if not applicable).
thanks in advance.Is this getString("name") method used over object "Resultset" ??
U can use getString(int) instead and specify the location of the "name" attributes
Example if the SQl looks like
select x.name,y.name,x.abc,x.temp form ... bla bla
x.name is getString(1);
y.name is getString(2);
Hope this helped you
Thanks
Sampath . -
I am trying to join two tables. I have a documents and uploads, of which user is common. For the user, I would like results put out from the tables where it is owned by the same user. So if they have two records in uploads, and one in documents, it puts all of those out. Also, how do I put out the data. For example, if it is a document, then access the document variables?
$sql="SELECT *
FROM documents
FULL JOIN uploads
ON documents.user = uploads.user";
Error:
Sql Error: Unknown column 'documents.user' in 'on clause'I've updated it:
$sql="SELECT *
FROM documents, uploads
WHERE documents.user = uploads.user AND documents.user='$profileIDNum'";
I get two test text files, but they have different date stamps some how. There is only one Test Text file in uploads. In documents, there are two records. I noticed when I change one of the dates for the records in documents, it changes the date for the Test Text file listed. -
Help needed with condition based joins in pl\sql
Hi,
I need to get data from 6 tables,
Scenario 1 : I need to join 4 tables and join this result set to 5th table
Scenario2: resultset of join of 4 tables to 6th table
In this case how do i save the intermediate result set of 4 tables to use it in further joins.Welcome to the forum.
Your question is broad.
http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
A more detailed example would help.
Mention your database version as well and see the FAQ http://forums.oracle.com/forums/help.jspa when it comes to posting formatted examples using the {noformat}{noformat} tag
However, i think using the WITH clause or a subquery ( a.k.a. inline view) is what you're looking for.
Do some searches on http://asktom.oracle.com to find many examples.
Also see:
http://www.oracle-base.com/articles/misc/WithClause.php
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries007.htm#sthref3193 -
Help with Inner Join query in SQL
Hope someone can help with this, as this is quite an involved project for me, and I'm just about there with it.
My table structure is :
table_packages
packageID
package
packageDetails
etc
table_destinations
destinationID
destination
destinationDetails
etc
table_packagedestinations
packageID
destinationID
..so nothing that complicated.
So the idea is that I can have a package details page which shows the details of the package, along any destinations linked to that package via the packagedestinations table.
So this is the last part really - to get the page to display the destinations, but I'm missing something along the way....
This is the PHP from the header, including my INNER JOIN query....
PHP Code:
<?php
$ParampackageID_WADApackages = "-1";
if (isset($_GET['packageID'])) {
$ParampackageID_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
$ParamSessionpackageID_WADApackages = "-1";
if (isset($_SESSION['WADA_Insert_packages'])) {
$ParamSessionpackageID_WADApackages = (get_magic_quotes_gpc()) ? $_SESSION['WADA_Insert_packages'] : addslashes($_SESSION['WADA_Insert_packages']);
$ParampackageID2_WADApackages = "-1";
if (isset($_GET['packageID'])) {
$ParampackageID2_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
mysql_select_db($database_connPackages, $connPackages);
$query_WADApackages = sprintf("SELECT packageID, package, costperpax, duration, baselocation, category, dateadded, agerange, hotel, educational_tours, field_trips, corporate_outings, plant_visits, budget_package, rollingtours, teambuilding, description, offer FROM packages WHERE packageID = %s OR ( -1= %s AND packageID= %s)", GetSQLValueString($ParampackageID_WADApackages, "int"),GetSQLValueString($ParampackageID2_WADApackages, "int"),GetSQLValueString($ParamSessionpackageID_WADApackages, "int"));
$WADApackages = mysql_query($query_WADApackages, $connPackages) or die(mysql_error());
$row_WADApackages = mysql_fetch_assoc($WADApackages);
$totalRows_WADApackages = mysql_num_rows($WADApackages);
$colname_educationalDestinations = "1";
if (isset($_GET['PackageID'])) {
$colname_educationalDestinations = (get_magic_quotes_gpc()) ? packageID : addslashes(packageID);
mysql_select_db($database_connPackages, $connPackages);
$query_educationalDestinations = sprintf("SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = %s ORDER BY destination ASC", GetSQLValueString($colname_educationalDestinations, "int"));
$educationalDestinations = mysql_query($query_educationalDestinations, $connPackages) or die(mysql_error());
$row_educationalDestinations = mysql_fetch_assoc($educationalDestinations);
$totalRows_educationalDestinations = mysql_num_rows($educationalDestinations);
?>
And where I'm trying to display the destinations themselves, I have :
<table>
<tr>
<td>Destinations :</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_educationalDestinations['destination']; ?></td>
</tr>
<?php } while ($row_educationalDestinations = mysql_fetch_assoc($educationalDestinations)); ?>
</table>
If anyone could have a quick look and help me out that would be much appreciated - not sure if its my SQL at the top, or the PHP in the page, but either way it would be good to get it working.
Thanks.First off, you need to get the database tables so that there is a relationship between them.
In fact, if there is a one to one relationship, then it may be better to store all of your information in one table such as
table_packages
packageID
package
packageDetails
destination
destinationDetails
etc
If there is a one to many relationship, then the following would be true
packages
packageID
package
packageDetails
etc
destinations
destinationID
packageID
destination
destinationDetails
etc
The above assumes that there are many destinations to one package with the relationship coloured orange.
Once you have the above correct you can apply your query as follows
SELECT *
FROM packages
INNER JOIN destinations
ON packages.packageID = destinations.packageID
WHERE packages.packageID = %s
ORDER BY destination ASC
The above query will show all packages with relevant destinations -
Case Insensitive search and "IN" Clause - Open SQL
Hi,
I have some doubts regarding Open SQL:
Is there any support for Case Insensitive Search in Open SQL, is it availabe by default?
Is there any restriction on number of elements in "IN" Clause, in Open SQL, is there any default number?
I have checked the [Open SQL Grammer|http://help.sap.com/saphelp_nwce711/helpdata/en/9b/f46cabaa874bc9a82234e8cf1d0696/frameset.htm] also, but nothing found there.
Thanks,
Piyush
P.S I didn't find any other appropriate place to post this thread, let me know the correct categorization of Open SQL in case its wrong.Is there any support for Case Insensitive Search in Open SQL, is it availabe by default?
When you are querying any strings, it is always case sensitive.
Is there any restriction on number of elements in "IN" Clause, in Open SQL, is there any default number?
I don't think there area any. IN opearator works like combined ORs and here you don't have any restrictions in fields number.
Regards
Marcin
Maybe you are looking for
-
I want to play videos and movies from the Apps on my iPad with iOS 6.1.2 on my Samsung HD TV, what cables etc. do I need?
-
I have a mac at home and at the office. Is there any reason for me not synch my phone with both computers?
-
Resubmission of workitem (CAT2)
For the CAT approval process I am using Approval by supervisor standard task , and for the agent determination I am using CATS approver BADI, due to problem in organization structure there are some org structures which have no supervisor assigned so
-
I am now moving my email service to Gmail and plan to connect it to my BB Tour using the Google Sync service. My Gmail account handles 2 email addresses- one Gmail address for personal, and a second address for business that uses a private domain ho
-
Why latest flash player 11 version is not available for download?
Flash player about page (http://www.adobe.com/software/flash/about/) is showing the latest flash player as 11.3.300.255 for windows where as flash player download page is showing 11.2.202.235 fow download. I have tried the following pages for downloa