Crystal Reports: expressions in table joining - crystal-reports

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.

Related

Get an Empty Column from a table when filter condition fetches empty in PostgreSQL

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

Select from view and join from one table or another if no record available in first

I have a view and two tables. Tables one and two have the same columns, but table one is has as small number of records, and table two has old data and a huge number of records.
I have to join a view with these two tables to get the latest data from table one; if a record from the view is not available in table one then I have to select the record from table two.
How can i achieve this with MySQL?
I came to know by doing some research in internet that we can't apply full join and sub query in from clause.
Just do a simple UNION of the results excluding the records in table2 that are already mentioned in table1:
SELECT * FROM table1
UNION
SELECT * FROM table2
WHERE NOT EXISTS (SELECT * FROM table1 WHERE table2.id = table1.id)
Something like this.
SELECT *
FROM view1 V
INNER JOIN (SELECT COALESCE(a.commoncol, b.commoncol) AS commoncol
FROM table1 A
FULL OUTER JOIN table2 B
ON A.commoncol = B.commoncol) C
ON v.viewcol = c.commoncol
If you are using Mysql then check here to simulate Full Outer Join in MySQL
are you trying to update the view from two tables where old record in view needs to be overwritten by latest/updated record from table1 and non existant records from table1 to be appended from table2?
, or are you creating a view from two tables?

Dynamic values to another SQL statement

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

GROUP BY in UPDATE FROM clause

I really need do something like that:
UPDATE table t1
SET column1=t2.column1
FROM table t2
INNER JOIN table t3
USING (column2)
GROUP BY t1.column2;
But postgres is saying that I have syntax error about GROUP BY clause. What is a different way to do this?
The UPDATE statement does not support GROUP BY, see the documentation. If you're trying to update t1 with the corresponding row from t2, you'd want to use the WHERE clause something like this:
UPDATE table t1 SET column1=t2.column1
FROM table t2
JOIN table t3 USING (column2)
WHERE t1.column2=t2.column2;
If you need to group the rows from t2/t3 before assigning to t1, you'd need to use a subquery something like this:
UPDATE table t1 SET column1=sq.column1
FROM (
SELECT t2.column1, column2
FROM table t2
JOIN table t3 USING (column2)
GROUP BY column2
) AS sq
WHERE t1.column2=sq.column2;
Although as formulated that won't work because t2.column1 isn't included in the GROUP BY statement (it would have to be an aggregate function rather than a simple column reference).
Otherwise, what exactly are you trying to do here?
In MariaDB/ MySQL this SQL work :
UPDATE table t1 left join (
SELECT t2.column1, column2
FROM table t2
JOIN table t3 USING (column2)
GROUP BY column2
) AS sq on t1.column2=sq.column2
SET column1=sq.column1;

How to use joins on Pro*C 10g?

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 (+)