Skip to content
Advertisement

Tag: join

SQL – Postgres string agg is giving duplicates

Im trying to collect the foreign key mapping from system tables. And I used this below query. query 1: But this won’t provide the Primary tables columns that are pointing as Fk. So I found this query on Stackoverflow. query 2 Now this query gives individual columns. Lets say there is a FK like (logid, item) then I’ll get two

Join many to many tables optionally

I have below tables User Intrest Hobby User_Intrest User_Hobby Now to find user ids who have both interests Eating and Sleeping I have written Output Same as above I also can find user ids with hobbies Smoking, Hiking, Browsing as below Output Now I want to mix these two optionally in a way that if only interests are passed then

A problem with a simple join taking too long to finish

I´m having trouble identifying who to fix this simple join. My problem is, after adding the column B.CIDPRODUCT IS NULL this query takes hours to finish. table BO_PRICER001 rows 286537 table BO_PRODUCTCONFIG rows 7934844 on the table BO_PRICER001 exists 15329 rows with null with B.CIDPRODUCT IS NULL the live query show this plan: and without this column the plan is:

t-SQL cartesian production of several tables

I would like to get a cartesian product of several tables in SQL (which are actually only one column, so no common key). For example: I tried CROSS JOIN, but I couldn’t find an example with multiple tables. Is the only way to do it is nesting? What if we have 15 tables to join that way… it creates a

Advertisement