Skip to content

Tag: if-statement

If statement with select in Postgresql

I’ve having trouble to do a if with select, e.g: In SQL Server I can do this: But in postgresql I don’t have any idea how handle this. I’ve tring some ways to do this, but unfortunately I have not success. Answer The syntax for an IF in Postgres (or rather PL/pgSQL) is IF … THEN &#8230…

SQL If Not Any From Left Join Else Left Join

I the following query and I only want the results from the first left join that returns results for the addresses (add1/2/3). Is it possible, or should I just return it all and filer the results later? For example, if add1 returns 1 address, add2 returns 1 address and add3 returns 3 addresses, I only want the…

Postgres syntax error at or near “IF”

I am new to postgres and I am working on an assignment of mine. I had to create a table with only 1 column and, then I was given this statement to run in on pgadmin III: when I run this I get this error: syntax error at or near “IF” I have already take a look at this 38.6.2.