Could I use LLBL Gen to JOIN columns between tables which don't have a relationship of primary-foreign keys? - llblgenpro

I have the following DB structure
Table1( ID1,Col1,Col2) and Table1( ID2,Col3,Col4)
Table1 and Table2 are separate table and don't have any relationships between them.
and I would like to achieve the following result
SELECT *
FROM
Table1 JOIN Table2 ON Table1.Col1= Table2.Col3
How could I achieve that using LLBL Gen Adapter.
Thanks.

Is there any specific reason you're not using the LINQ statements?
Otherise that would make it easy:
Linq to LLBLGen Pro:
http://www.llblgen.com/documentation/3.1/LLBLGen%20Pro%20RTF/hh_start.htm
http://www.llblgen.com/documentation/3.1/LLBLGen%20Pro%20RTF/Tutorials%20and%20examples/examples_howdoi.htm#linq
Other options:
Define model-only relations in the LLBLGen Pro UI (since 3.0 only if the DB types + lengths match exactly unfortunately)
Have a look at instantiating a EntityRelation (however due to LINQ my Predicate skills are getting a bit rusty)

Related

updating a table in VFP

There are two tables in my database. I am trying to update a column in table2 by setting it equal to one of the columns in table1. I've already looked at this answer visual foxpro - need to update table from another table
And tried to do this on my code, however, I kept having a syntax error on UPDATE table2. Why?
Here is what I have.
ALTER TABLE table2;
ADD COLUMN base2 B(8,2);
UPDATE table2
WHERE table2.itemid=table1.itemid from table1;
SET table2.base2=table1.base;
The simplest syntax is:
update table2 from table1 where table2.itemid = table1.itemid ;
set table2.base2 = table1.base
You could also add more fields to update separated by commas, i.e.
... set table2.base2 = table1.base, table2.this = table1.that
Using 'standard' VFP language syntax and RELATED Tables, you could quite easily do the following:
USE Table1 IN 0 EXCLUSIVE
SELECT Table1
INDEX ON ID TAG ID && Create Index on ID field
USE Table2 IN 0
SELECT Table2
SET RELATION TO ID INTO Table1
REPLACE ALL Table2.ID WITH Table1.ID FOR !EMPTY(Table2.ID)
You might want to spend some time looking over the free, on-line tutorial videos at: Learn Visual Foxpro # garfieldhudson.com
The videos named:
* Building a Simple Application - Pt. 5
and
* Q&A: Using Related Tables In A Report
Both discuss using VFP's language to work with Related Tables
Good Luck
Use join
Update table2 b
Join table1 a on b. Itemid=a.itemid
Set b. Base2=a.base

Combine Multiple Hive Tables as single table in Hadoop

Hi I have multiple Hive tables around 15-20 tables. All the tables will be common schema . I Need to combine all the tables as single table.The single table should be queried from reporting tool, So performance is also needs to be care..
I tried like this..
create table new as
select * from table_a
union all
select * from table_b
Is there any other way to combine all the tables more efficient. Any help will be appreciated.
Hive would be processing in parallel if you set "hive.exec.parallel" as true. With "hive.exec.parallel.thread.number" you can specify the number of parallel threads. This would increase the overall efficiency.
If you are trying to merge table_A and table_b into a single one, the easiest way is to use the UNION ALL operator. You can find the syntax and use cases here - https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Union

How to populate columns of a new hive table from multiple existing tables?

I have created a new table in hive (T1) with columns c1,c2,c3,c4. I want to populate data into this table by querying from other existing tables(T2,T3).
E.g c1 and c2 come from a query run on T2 & the other columns c3 and c4 come from a query run on T3.
Is this possible in hive ? I have done immense research but still am unable to find a solution to this
Didn't something like this work?
create table T1 as
select t2.c1, t2.c2, t3.c3, t3.c4 from (some query against T2) t2 JOIN (some query against T3) t3
Obviously replace JOIN with whatever is needed. I assume some join between T2 and T3 is possible or else you wouldn't be putting their columns alongside each other in T1.
According to the hive documentation, you can use the following syntax to insert data:
INSERT INTO TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...)] select_statement1 FROM from_statement;
Be careful that:
Values must be provided for every column in the table. The standard SQL syntax that allows the user to insert values into only some columns is not yet supported. To mimic the standard SQL, nulls can be provided for columns the user does not wish to assign a value to.
So, I would make a JOIN between the two existing table, and then insert only the needed values in the target table playing around with SELECT. Or maybe creating a temporary table would allow you to have more control over the data. Just remember to handle the problem with NULL, as stated in the official documentation. This is just an idea, I guess there are other ways to achieve what you need, but could be a good place to start from.

How to select row data as column in Oracle

I have two tables like bellow shows figures
I need to select records as bellow shown figure. with AH_ID need to join in second table and ATT_ID will be the column header and ATT_DTL_STR_VALUE need to get as that column relevant value
Required output
Sounds like you have an Entity-Attribute-Value data model which relational DBs aren't the best at modeling. You may want to look into a key-value store.
However, as Justin suggested, if you're using 11g you can use th pivot clause as follows:
SELECT *
FROM (
SELECT T1.AH_ID, T1.AH_DESCRIPTION, T2.ATT_ID, T2.ATT_DTL_STR_VALUE
FROM T1
LEFT OUTER JOIN T2 ON T1.AH_ID = T2.AH_ID
)
PIVOT (MAX(ATT_DTL_STR_VALUE) FOR (ATT_ID) IN (1));
This statement requires you to hard-code in ATT_ID however there are ways to do it dynamically. More info can be found here.

Linq to Entity Query .Expand

I got the following tables
TableA, TableB, TableC, TableD, TableE and they have foreign key relations like
FK_AB(one to many),FK_BC(one to one),FK_CD(One to many),FK_DE(one to one) and have the navigation properties based on these foreignkeys
Now I want to query TableA and get the records from TableA, TableD and TableE whoose Loadedby column equal to System. My query is like below
var query= from A in Context.TableA.Expand(TableB/TableC/TableD).Expand(TableB/TableC/TableD/TableE)
where A.Loadedby=="System"
select A;
The above query is working fine. I want the records from TableD and TableE whoose Loadedby value equal to System but the above query returning all the records from TableD and TableE which are related to TableA record satisfying A.Loadedby="System" this condition is not checked in the child tables.
Can anyone tell me how to filter the child tables also.
Currently OData only supports filters on the top-level. So in the above example it can only filter rows from the TableA. Inside expansions all the approriate rows will be included, always, there's no way to filter those right now.
You might be able to ask for the exanded entities separately with additional queries (with the right filter) and possibly use batch to group all the queries in one request. But that depends on the actual query you need to send.

Resources