I am looking for a SQL query. Table 1: Source Table Table 2: Result Table Attached the patient table. Here I want to find the Highest Score, Highest Score Date, Lowest Score and Lowest Score Date of …
elect data from related tables with duplicate columns
I have 3 tables. news rubrics parent_id is key for id parent in table rubrics. And “news_rubriks” How I can select news which apply to rubrics.id and rubrics.parent_id ? Answer If I understand correctly, you want to apply a filter to both the rubrik id and the parent. Say if you are searching for …
Select when two tables reference the same table
I have two tables, tSellers and tBuyers. They both have FK to a table tCity. How do I join and select city name from a buyer and a seller in a order table? Expected output: Answer To expand on @jarlh ‘s comment: Example of joining on City table twice, once for Seller (to get the city of the Seller), and
MySQL: cannot add constant field at start of SELECT. Error 1064
Using MariaDB v. 10, I try to add a custom constant as the first column of my SELECT query, before all other columns *. This results in the generic syntax error 1064. For example: If I select only some columns, it works: And it also works if I use * to select all columns, but put my constant column after
Case Statement within in Statement in MS SQL
I want to compare two different tables in IN statement based on condition. SELECT DISTINCT cts.ContactType ,ISNULL(ctl.[Description], CONCAT(‘Unknown Contact Type: ‘,cts.ContactType)) …
SQL Nested Joins (Case Statement and Join)
Hive DBMS; Two tables — A and B Table A Table B Question –> Trying to execute a query where: Join table A with table B, first on prnt_id, if it’s “unknown”, then join on sub_id, if that is “unknown”, join on ac_nm Desired Output: Answer You must use LEFT joins of T…
Converting date and time TEXT fields to one INT unix timestamp field in SQL
I currently have a mySQL database with two TEXT fields: Date and Time. These are in the format ‘dd/mm/yyyy’ and ‘0:00′ respectively, for example ’11/08/2020’ and 19:12. I want to create a third field …
column creation on condition – sql
Table: col1 col2 col3 236 1234 lion 236 1234 235 1023 235 1234 234 1234 232 1234 232 1234 …
Postgres declaration type for multiple rows
I have a postgres function that uses a %ROWTYPE declaration. When I execute this function I get a failure about returning more than one row “code”:”P0003″,”message”:”…
Group by expression with case statement in oracle?
I have a query with case statement in it. This query gives me error ORA-00979: not a GROUP BY expression When I remove my last case statement from select then it runs fine. Please help me in this Answer Columns that aren’t aggregated should be part of the GROUP BY clause. It means that “solution&#…