Skip to content

Print a custom message when no rows are returned by a SELECT statement

I am trying to create a report of INVALID objects in Oracle. The requirement is to print a custom message when no rows are returned (This is because the output will be redirected to an HTML report). I tried the following query: Error am seeing: While the individual queries work without an issue, it fails to e…

Select one of two columns based on their value in SQL

I have a scenario where I have a users table where users are connections to each other based on the connections table. The connections table has a user_id1 field and a user_id2 field. I want to get the connections for a specific user: But the user_id’s of the connections are separated into two columns. …

mysql query error: SQL sum with condition

This is my code: select assignedstfid, staffname, staffsymbol, SUM(case where bookingstarttime > ‘2021-03-31’ then TIMESTAMPDIFF (minute, bookingstarttime, bookingendtime) else 0 end) as …

Interval to previous row

I would like to get the interval between the rows in my table. When I use this query I get seconds from previous timestamp. But the result is only right when two timestamps is in the same minute. …

Syntax error while using WHERE clause in PostgreSQL

I’m trying to run some queries related to the University database in PostgreSQL. To find students advised by instructors from different departments, I used- However im getting the following error: ERROR: syntax error at or near “where” LINE 3: student join instructor where student.dept_name …