sql - Query returns no records -
hello making schema purchasing orders these orders can ordered user , received user.
so created below schema.
schema
the issue when userid
column in purchaseorders
, deliveries
tables has different values query returns no records.
query
select dbo.users.firstname, dbo.users.lastname, dbo.purchaseorders.purchaseorderdate, dbo.deliveries.expecteddeliverydate, dbo.deliveries.actualdeliverydate dbo.purchaseorders inner join dbo.users on dbo.purchaseorders.userid = dbo.users.userid inner join dbo.deliveries on dbo.purchaseorders.purchaseorderid = dbo.deliveries.purchaseorderid , dbo.users.userid = dbo.purchaseorders.userid , dbo.users.userid = dbo.deliveries.userid
you need 2 different joins users
. need learn use table aliases:
select pu.firstname purchase_firstname, pu.lastname purchase_lastname, du.firstname delivery_firstname, du.lastname delivery_lastname, po.purchaseorderdate, d.expecteddeliverydate, d.actualdeliverydate dbo.purchaseorders po join dbo.deliveries d on po.purchaseorderid = d.purchaseorderid join dbo.users pu on p.userid = pu.userid join dbo.users du on d.userid = du.userid;
your query returns no records because of condition:
, dbo.users.userid = dbo.purchaseorders.userid , dbo.users.userid = dbo.deliveries.userid
this means dbo.purchaseorders.userid = dbo.deliveries.userid
. so, if not true, no records match condition.
Comments
Post a Comment