Skip to content

SQL WHERE condition when one does not return true, then try other

I have to query a table based on two fields such that if first field matches then don’t check the second but if first field does not match then check if second field matches for a value something like: But if first condition succeeds, it must not check for second condition Example: Suppose the following…

SQL CASE WHEN won’t meet condition

This is a solution to one of the leetcode problem. It is asking me to output the second highest salary from the table and if there are no second highest salary then the output should be null. The above is my solution. I used case and when syntax but the problem is that even when the table only has 1

Not able to create a matrix in PL/SQL using nested tables

I was trying to create a matrix in PL/SQL using nested tables as such: firstly, I create a table type that is able to store varchars (that in my case is name lista_principala) secondly, using the previously declare table type lista_principala I try to create a table type that contains items of type lista_prin…

Return all values from objects using OPENJSON()

Here is my problem: My JSON may vary based on API response and there is no guarantee that “shortTitle”, for example, can be present in my JSON next time when there is a post request. I have to figure how to “loop” (if that’s the correct term) through JSON to get all fieldID and c…

How to vertically flip the column values top to down in SQL

How to vertically flip the column values from top to bottom in SQL which are not in any specific order(neither asc nor desc)? Example: Table named ‘Country’ has a single column c1 with values Now I want to display the Result-set as below: If anyone can kindly suggest? Answer It’s not possibl…

Duplicated inner join results

With postgres I’m trying to get a single user and all their posts, but when I inner join the Users and Posts tables I receive this: QUERY: I’m also trying to do the same thing but as a json QUERY: I know why but I don’t know how to avoid it, can someone help me to get something like this: