I have 3 tables in the same database, with couple of columns as common and rest non-matching columns as well. I need to show them together in such a fashion that the user should be able to distinguish between the source tables (Refer below diagrams). I want to know if I can achieve this in database itself, before passing its result on to my report UI or code behind?
I have tried achieving this using OUTER JOIN, FULL OUTER JOIN.
See here
Also here
Related
I think I got a knot in my line of thought, surely you can untie it.
Basically I have two working queries which are based on the same table and result in an identical structure (same as source table). They are simply two different kinds of row filters. Now I would like to "stack" these filters, meaning that I want to retract all the entries which are in query a and query b.
Why do I want that?
Our club is structured in several local groups and I need to hand different kinds of lists (e.g. members with email-entry) to these groups. In this example I would have a query "groupA" and a query "newsletter". Another could be "groupB" and "activemember", but also "groupB" and "newsletter". Unfortunately each query is based on a set of conditions, which imho would be stored best in a single query instead of copying the conditions several times to different queries (in case something changes).
Judging from the Venn diagrams 1, I suppose I need to use INNER JOIN but could not get it to work. Neither with the LibreOffice Base query assistant nor an SQL-Code. I tried this:
SELECT groupA.*
FROM groupA
INNER JOIN newsletter
ON groupA.memberID = newsletter.memberID
The error code says: Cannot be in ORDER BY clause in statement
I suppose that the problem comes from the fact, that both queries are based on the same table.
May be there is an even easier way of nesting queries?
I am hoping for something like
SELECT * FROM groupA
WHERE groupA.memberID = newsletter.memberID
Thank you and sorry if this already has a duplicate, I just could not find the right search terms.
My professor stated that certain queries need to use a view, instead of a join because a join will calculate values multiple times - producing an incorrect result. Why does this happen? And how does a view protect from that?
If you're using a view in place of a join then your view probably contains a join. A view is simply a stored query. It presents to you a virtual single table but may be made up of joins across many tables, or it may contain aggregated data.
Based on that, I'm assuming there is more to your professors logic because your statement doesn't make sense.
I am developing a small web app (angularjs/jquery front end, postgresql 9.3 backend) in which I want to present a view of a largish (few million) set of records in a "grid" (read-only). I have a set of filters based on facets of the data that I would like the user to be able to apply serially; that is, one filter is applied and then the next filter is applied. The user can choose both the filters and the filter settings. This ends up being a set of logical AND operations (perhaps requiring SQL joins, as well).
I am interested in what folks do on the backend to improve the user experience. In particular, I can imagine:
Apply filters "dynamically" as a SQL query whenever pagination or additional filtering is applied
Create a cache at each level of filtering so that I can update data more quickly
There are clearly other options and I would like to hear what others would do in this situtation.
Not sure the question is “answerable”, but here’s example of what we’ve done. We have application that does not do filtering but rather allows the use to select which data items that want to see. Like your application, these could include joins to multiple other tables. We have a “driver” table that has the “user” version of the field name, a string for the inner join to the table that contains it, optionally a string for the Where clause if the inner join condition is not sufficient, and the name of the column on the DB.
We build the base query then look at the entries for all the items the user has selected. We add distinct inner join clauses form those fields (if three columns are coming from one table, we only want to join it once). We add And clauses to the Where clause encapsulation in parenthesis. And we add the column names to the select list.
I have a Data Flow Task that does some script component tasks, sorts, then does a Merge Join. I'd like to have the Merge Join do the join as a 1-many. If I do an Inner Join, I get too few records:
If I do a Left Outer Join, I get WAY too many records:
I'm looking for the Goldilocks version of 'Just Right' (which would be 39240 records).
You can add a Conditional Split after your left join version of the Merge Join, with a non-matching condition like
isnull(tmpAddressColumn)
and send the relevant matching flow condition (the default output) to your destination.
If you still don't get the correct number, you'll need to check the merge join conditions and check if there are duplicate IDs in each source.
The number of rows shouldn't be what you're using to gauge if you're using the correct options for the Merge Join. The resulting data set should be the driving factor. Do the results look correct in the tmpManAddress table?
For development you might want to push the output of the script components to tables so you can see what data you're starting with. This will allow you to work out which type of join, and on which columns, give you the results you want.
I have one app with one database, and I need to make a replication of some of those tables, and also include one new table which is a join of more than one of those tables.
I tried transaction replication, but the filter for the tables only allows me to modify the 'where' clause.
Anybody can help me with this?
I'd replicate the two tables in question as-is, then create a view on the subscriber to represent your desired join.