SubSonic 3 ActiveRecord Fluent Query Multiple Join - join

I'm trying to do a multiple join to a second column that is referenced from the first join. So in effect find out which stores the product is in.
var q = new MyDB().SelectColumns(Store.NameColumn)
.From<Product>()
.InnerJoin<Shelf>(Product.ShelfIdColumn, Shelf.IdColumn)
.InnerJoin<Store>(Shelf.StoreIdColumn, Store.IdColumn)
.Where(Product.IdColumn).IsEqualTo(5);
The problem is that SubSonic is trying to join the Store table directly to the Product table. I see in the source the comment:
//the assumption here is that the FromTable[0] is the table to join from
So every join is going to be attempted on the Product table. 2.1 had the option of passing in qualified names for the join. Is there a way around this or should I start writing my own fix to allow me to pass in qualified names again?

Related

PowerBI - Join DirectQuery and Imported tables in DAX

I have a DirectQuery table (Weather) which is sourced from an Azure SQL server. I would like to join this with an Imported table (Buckles) from an Excel sheet sourced from SharePoint Online.
Both tables have a UID field that is made up of a concatenation between a SiteID and timestamp. The UID field is named differently for each table.
I have created a One-To-Many relationship between the two tables.
I have tried to create a new DAX table using a NATURALINNERJOIN on Weather and Buckles but I get this error:
"No common join columns detected. The join function 'NATURALINNERJOIN' requires at-least one common join column."
I am confident it is not a problem with the underlying data because I've created a new imported Excel table (Test) with a selection of the data from Weather and I'm able to successfully create the join on Test and Buckles.
Is the joining of DirectQuery and Imported tables supported? I feel like this may be a type casting issue, but as far as I can see, both UID fields are set as Text.
The UID field is named differently for each table.
I suspect this may be the issue. NATURALINNERJOIN looks for matching column names
and if the two tables have no common column names, an error is returned.
Note that if you create a calculated DAX table using a DirectQuery source, I don't think that table will still act like DirectQuery. If I understand correctly, it will materialize the calculated table into your model and DAX that references that calculated table no longer points back to the SQL server (and consequently will only update when the calculated table gets rebuilt).

How to join two tables in HTSQL specific to any columns

HTSQL works when two tables are properly linked with foreign key.
For example:
school can be easily joined with department if we have properly defined a foreign key say school_code of department table referencing code of school.
So far I'm not able to find any way to join two tables on some other columns.
Can any one help me how to do this in HTSQL?
The tweak.override extension allows you to define foreign-keys in a config file even if they're not present in the database itself. http://htsql.org/doc/admin/usage.html#extension-reference
tweak.override:
foreign-keys:
- program(school_code) -> school(code)
- program(school_code, part_of_code) -> program

Rails where two tables have the same data?

I'm trying to create a table in my view and populate it on some conditions.
I have two tables, Both have two columns inside, One columns called event_url and the other is gmiurl. The table with gmiurl inside is called GMITable and the other is called newevent
Basically i want to show everything inside the GMITable unless the column event_url has a url inside that matches to any of the urls inside gmiurls inside the GMITable
I dont have anycode for this apart from this at the moment
#GMI = GMITable.all
You can easily achieve the result by using a LEFT OUTER JOIN from Table A to Table B, as described in this visual explanation.
Specifically, what you want is:
To produce the set of records only in Table A, but not in Table B, we perform the same left outer join, then exclude the records we don't want from the right side via a where clause.
In your question is not clear how the tables are called, and how they relate each other. However, to achieve the result simply perform a join between the tables using the ActiveRecord join method
TableA.joins('LEFT OUTER JOIN TableB on TableA.field = TableB.field')
and select only the items where(TableB.id IS NULL).
You'll have to adapt the example to your needs.

Join queries in Doctrine on tables without specified relations

I have two tables that do not have a relation defined with each other in the schema.yml.
However, table 1 has a foreign key reference to the primary key of table 2. Clearly, I goofed up by not designing the database well, but now it's mitigation time.
I must do a left join between the two tables coupled with a where clause that will retrieve the select rows I want. And to do this, I do:
Doctrine_Query::create()->select('t.*, l.lid')->from('Taxonomy t')->leftJoin('t.Cid c') ->leftJoin('c.Lesson l')->where('t.section = ?','Critical reading');
This should typically do it, but it does not because what it returns is all the rows from taxonomy table irrespective of the where condition. I am thinking, is this because of the relation not being specified in the column? That would be ridiculous cause the query works, only in a doctrine context it does not.
Thanks
In doctrine you can only join using the relations you defined on your schema, this is a know limitation. You may use the Native SQL feature as a workaround.

Deleting rows in joined tables using ADO

Now I have seen this question in another forum but it didn't had an acceptable answer.
Suppose I have two tables, the Groups table and the Elements table. The tables have no defined relationships. The Elements table has an IdGroup field that refers to the IdGroup (PK) field of the Groups table.
I use the following query through an ADO recordset to populate the tables values to a datagrid:
SELECT Elements.*, Groups.GroupName
FROM Elements
INNER JOIN Groups ON Elements.IdGroup = Groups.IdGroup
From that grid I want to press Delete in order to delete an Element. Here is my problem. When I used DAO, the DAO Delete() function deleted only the record in the Elements group. This was the expected behavior.
When I changed to ADO, the Delete() function deleted records in both tables, the element record and the group to which the element belonged!
Is there any way to reproduce the DAO behavior in ADO without having to define relationships into the tables?
Note: I know there are alternatives (executing DELETE querys could do the job). Just show me a way to do this in ADO, or say it cannot be done.
Rewrite you query to:
replace the INNER JOIN with a WHERE clause consisting of an EXISTS;
use a subquery in the SELECT clause to return the value of Groups.GroupName.
Example:
SELECT Elements.*,
(
SELECT Groups.GroupName
FROM Groups
WHERE Elements.IdGroup = Groups.IdGroup
)
FROM Elements
WHERE EXISTS (
SELECT *
FROM Groups
WHERE Elements.IdGroup = Groups.IdGroup
);
I've tested this using SQL Server 2008 with a ADO recordset set as the DataSource property of a Microsoft OLEDB Datagrid Control (MSDATGRD.OCX) then deleting the row via the gird (I assume you are doing something similar) and the row is indeed deleted from table Elements only (i.e. the row in Groups remains undeleted).
Note the revised query may have a negative impact on performance when fetching rows.

Resources