How do I find missing data [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have to find riskunits.descriptions that are missing on policies.
I can match riskunitid on policyid - but how do I find a policy that does not have a riskunit.description? I am new to SQL

Not knowing your exact table structure, we'll have to make do with some pseudo code:
select *
from policy p
where not exists (
select *
from riskunit r
where r.policyid = p.policyid
)
This will find policies with no riskunit record. If you expect there will always be a riskunit record, but the description may be null or an empty string, go with this instead:
select *
from policy p
join riskunit r
on r.policyid = p.policyid
where (r.description is null or r.description = '')

Related

SQL Join...Issue with joins [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I need help regarding SQL joins, i am trying join two tables as shown in below images
I guess you can try the below query to get the desired result -
SELECT CASE WHEN CT.partner2 IS NULL
THEN C.partner_id
ELSE CT.partner1
END Partner1,
CT.partner2,
C.Type,
C.Company_name,
C.First_name,
CT.city,
CT.Phone,
CT.Email
FROM CUSTOMER C
LEFT JOIN CONTACTS CT ON C.partner_id = CT.partner2

Get CR_NO values for the same table in sql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Some can help me on this query? I need this
You can use the exists as follows:
Select cr_no, so, id
From your_table t
Where exists (select 1 from your_table tt
Where t.cr_no <> tt.cr_no
And t.so = tt.so
And t.id = tt.id)

What would be the SQL query for this? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
List the name of all clients who have viewed a property based on the UML graph
SELECT [C-NAME]
FROM [CLIENT]
JOIN [PROPERTY]
ON CLIENT.CLIENTID = PROPERTY.PROPERTYID
If I've understood that UML model you can't, View-Appointment needs ClientID and PropertyID adding.
Then you can do, to give all clients that have an appointment (obviously adding a WHERE on the date column will give you future/past appointments):
select [C-Name] from [Client] inner join [View-Appointment] on Client.ClientID = View-Appointment.ClientID;
If you want property details in the query then you need another inner join:
inner join Property on Property.PropertyID = View-Appointment.PropertyID

How can I get the Unit Number to be displayed in place of the "ID" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How can I write a SQL query that will replace the "ComputerID" and "PartID" with the "UnitNumber". The ComputerID's and PartID's are in the same column under InventoryID. The InventoryID's are unique but the UnitNumber (sticker label/name) doesn't have this requirement.
Here are the tables and how they relate.
Let's call your tables Object and Inventory
If you use a couple of joins then this should work:
select o.ObjectID as ObjectID, a.UnitNumber as Computer, b.UnitNumber as Part,
o.InputID from Object o
join Inventory a on a.InventoryID=o.CombputerID
join Inventory b on b.InventoryID=o.PartID

DB2, optimize an update query [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have this query:
update product a
set a.tsinsert = (select b.tsinsert
from h_product b
where b.tsinsert is not null and
a.product_id = b.product_id);
This query doesn't end.
Can I write it otherwise?
I used this query and it works:
merge into product a using (select distinct product_id ,TSINSERT from h_product where tsinsert is not null order by product_id ) b
on (a.product_id = b.product_id )
when matched then update set a.tsinsert = b.TSINSERT;
For this query:
update product a
set a.tsinsert = (select b.tsinsert
from h_product b
where b.tsinsert is not null and
a.product_id = b.product_id);
You want an index on h_product(product_id, tsinsert). I am surprised that the query doesn't have a where clause, because this will set a.tsinsert to NULL when there are no matches.