Skip to content

Count from 4 tables with join and null values

Tables: What I am expecting to query is this: However this is what I get: With this query: I wonder, in what way the query above could be modified to return the expected results? What would be a good approach to achieve this? Answer You are joining along two dimensions, so you are getting a Cartesian products…

SQL query Postgres 12

I’m doing an inner join on a table like this: The condition f.vac_1 = mv.id might not been satisfied in the case where a person have not been vaccinated. In such case, I don’t want to ignore the row, but instead of displaying the vaccine name (which is the purpose of the inner join) to display an …

What is wrong with my stored procedure SQL query on PostgreSQL?

I tried many times with or without the semicolon but still shows me the error message. ERROR: syntax error at or near “INSERT” LINE 13: INSERT INTO Advertisement(ad_id, business_id, requested_on… ^ SQL state: 42601 Character: 712 I am sure the table constraint and sequence are all correct bu…

SQL select query retrieval blank return

I have to retrieve distinct entities from a column, all of which start with a vowel. The query looks like this : It’s not giving compilation errors, but it’s not returning anything. Any ideas? Answer You can use regular expressions: LIKE wildcard patterns do not support character classes, except i…

How to use two where conditions in SQL?

Following is the query I have written and I need to where conditions. Admin_Level_3_palika is not null Year = ‘2021’ However, the following query is still giving me null values for Admin_Level_3_palika Please help me with how to work with this. Following is an example of my dataset, Epid_ID being …

SQL subqueries PostgreSQL 12

I’m having a table similar to this: first last date pos john doe 18-03-2021 harris potter 10-06-2021 john doe 10-05-2021 harris potter 14-06-2021 jessica potter 14-06-2021 kermit foster The use case is as follow: The pos column correspond to a positive covid test The date column correspond to the vaccin…