Skip to content

Tag: sql

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, i…

Postgres how to return values in between Min column and Max column

totally new in learning postgres/SQL I have a table called error_table that looks like this: but I am having a hard time generating a query on how to do this dynamically when my input number is 160, I would like to return the error_percent value 4.6 because 160 sits between the min column 100 and max column 2…

Select statement using Chinese characters

i have a table store chinese address and english address i need to select address for compare which address do not same. when i select english address can compare which one different but chinese address cannot. anybody advise? thanks For Example: i want to output Answer Ok, you can use left join like below sa…

Populate DTO using query with JOIN

I have this main Product table: Additional table for storing categories that should be returned as List: Additional table for storing Payment Methods that should be returned as List: I want to return a result like this: I tried this: What is the proper way to populate this DTO? Answer If, as indicated in your…

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 inter…

Get all values from intermediate table

I have a mySQL three-table many-to-many setup with link table, simplified here: categories category_id category_name categories2entries category_id, entry_id entries entry_id entry_text …

I am missing an alias for a derived table

I know, this question has been asked very often but I know my error, I know how I could fix it, but I can´t find the point where the error is. In my opinion, all the subqueries have different and …