While using inner join on Pro*C I am getting the below error:
PCC-S-02201, Encountered the symbol "inner" when expecting one of the following:
I've just used a simple inner join. When I searched for solution, I was told that 10g doesn't support these kind of syntax and I should use dynamic SQL instead. Is that true? How to achieve inner join using dynamic SQL?
ProC 10g version doesn't allow inner/outer joins. If you want to have these, you will have to upgrade your ProC compiler.
If you use, 11g you can use the solution suggested here: http://forums.oracle.com/forums/thread.jspa?threadID=665519
Use the old syntax.
Instead of: SELECT * FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.PK = TABLE2.FK
Use this: SELECT * FROM TABLE1, TABLE2 WHERE TABLE1.PK = TABLE2.FK
For OUTER JOINS just use the (+) sign on the side you want to be nullable:
Instead of: SELECT * FROM TABLE1 LEFT JOIN TABLE2 ON TABLE1.PK = TABLE2.FK
Use this: SELECT * FROM TABLE1, TABLE2 WHERE TABLE1.PK = TABLE2.FK (+)
Related
I am having trouble using the LIMIT Statement. I would really appreciate your help.
I am trying to INNER JOIN three tables and use the LIMIT statement to only query a few lines because the tables are so huge.
So, basically, this is what I am trying to accomplish:
SELECT *
FROM ((scheme1.table1
INNER JOIN scheme1.table2
ON scheme1.table1.column1 = scheme1.table2.column1 LIMIT 1)
INNER JOIN scheme1.table3
ON scheme1.table1.column1 = scheme1.table3.column1)
LIMIT 1;
I get an syntax error on the LIMIT from the first INNER JOIN. Why? How can I limit the results I get from each of the INNER JOINS. If I only use the second "LIMIT 1" at the bottom, I will query the entire table.
Thanks a lot!
LIMIT can only be applied to queries, not to a table reference. So you need to use a complete SELECT query for table2 in order to be able to use the LIMIT clause:
SELECT *
FROM schema1.table1 as t1
INNER JOIN (
select *
from schema1.table2
order by ???
limit 1
) as t2 ON t1.column1 = t2.column1
INNER JOIN schema1.table3 as t3 on ON t1.column1 = t3.column1
order by ???
limit 1;
Note that LIMIT without an ORDER BY typically makes no sense as results of a query have no inherent sort order. You should think about applying the necessary ORDER BY in the derived table (aka sub-query) and the outer query to get consistent and deterministic results.
I have two tables table1(id,name,type) and table2(id,source,destination)
When I run query
SELECT
name,
source,
destination
FROM
table1,
table2
WHERE
table1.id=table2.id
If there's no id matching between two tables, can I still get empty column for source and destination .
Yes, you basically want an OUTER JOIN and remember to always use the explicit ANSI JOIN syntax and not the implicit comma syntax for joins.Also use proper table aliases to avoid ambiguity.
SELECT
t1.name,
t2.source,
t2.destination
FROM
table1 t1 left outer join
table2 t2 ON t1.id = t2.id
Is there a way to combine two SQL queries into a single SELECT query in PostgreSQL?
My requirements are as follows:
SELECT id FROM table1;
SELECT name FROM table2 WHERE table2.id = table1.id;
I think I need to pass values of table1.id in as some sort of dynamic values (loop values) for use in the SELECT statement executed on table2. What is the easiest way to solve this problem, is it possible to do this with stored procedures or functions in PostgreSQL?
select t1.id, name
from
table1 t1
inner join
table2 t2 using (id)
where t1.id = 1
Is it possible to join tables in Crystal Records by using not simple and usual field A = field B but something more complex like:
select * from table1 inner join table2
on table1.A=2*table2.B
or
select * from table1 inner join table2
on ASCII(table1.A)=ASCII(table2.B)
Use a single Command instead of tables in the Database Expert. You will be able to use more-complex SQL.
Why this simple query works fine in oracle but doesn't work in DB2:
select *
from
sysibm.dual d1
left join sysibm.dual d2 on 1=1 and exists (select 1 from sysibm.dual)
Moving subquery-involving condition to where clause may help, but that will restrain outer join into inner.
When I try to run the query you have, I get a -338 error, which according to Information Center (see link), there are the following restrictions on the ON clause:
An ON clause associated with a JOIN operator or in a MERGE statement
is not valid for one of the following reasons.
* The ON clause cannot include any subqueries.
* Column references in an ON clause must only reference columns
of tables that are in the scope of the ON clause.
* Scalar fullselects are not allowed in the expressions of an ON clause.
* A function referenced in an ON clause of a full outer join
must be deterministic and have no external action.
* A dereference operation (->) cannot be used.
* A SQL function or SQL method cannot be used.
* The ON clause cannot include an XMLQUERY or XMLEXISTS expression.
I'm not sure if it's possible with your query, but do you think perhaps you could re-write something like this:
select *
from
sysibm.dual d1
left join (
SELECT dl.*,
CASE WHEN EXISTS (SELECT 1 FROM sysibm.dual)
THEN 1
ELSE 0
END AS jn
FROM sysibm.dual dl
) D2
on 1=1 and 1=d2.jn
This works in DB2 V10.1!
No fixpack installed.