Last post Jun 07, 2019 03:17 AM by Brando ZWZ
Jun 06, 2019 07:39 AM|Manishamani|LINK
Jun 06, 2019 07:54 AM|AddWeb Solution|LINK
Try with this below example,
Assuming the primary key of children is (horror) id:
from parents p
inner join children c on c.parentId = p.id
where c.firstname like 'tom'
and not exists
( select 1 from children c2
where c2.parentId = p.id
and c2.id <> c.id
or using GROUP BY:
from parents p
( select parentid
from children c
group by parentid
having min(id) = max(id) -- you could use instead: count(*)=1 here
and min(firstname) like 'tom'
on c.parentid = p.id ;
Jun 06, 2019 08:34 AM|Manishamani|LINK
Jun 06, 2019 11:47 AM|AddWeb Solution|LINK
As per your description and what i understood , I have implemented this query with parent and multiple child tables.
select top 1 u.Id,lu.cnt,lu.UserId,cu.scnt,cu.cuid from (
select * from [dbo].[parent] where Deleted=0
left outer join (select COUNT(*)cnt,UserId,Deleted from [dbo].[child1] where Deleted=0 group by UserId,Deleted)lu
left outer join (select COUNT(*)scnt,UserId cuid,Deleted from [dbo].[child2] where Deleted=0 group by UserId,Deleted)cu
-- if multiple table then Like This type of define
where cnt=1 and scnt=1
-- in where conditon to check count =1
If it is not scenario than post your question with your schema(tables) , so i can try to give you accurate solution.
Jun 07, 2019 03:17 AM|Brando ZWZ|LINK
Not working. Need to get data from multiple tables also
According to your description, I couldn't understand your requirement clearly.
Do you mean you want to query just one record from another query which use inner join to select multiple tables?
Could you please tell me what is the architecture of the tables and result you want to get from the tables?