Friday, March 9, 2012

Dont want every row i second table

Hi!

I've got 2 tables that are related

Tabel 1
CatID
CatName

Table2
SubID
CatID
SubName
(So this table can have more than one related CatID, but I would like to only retreive 1 row)

I've tried the diffrent Joins to get what I want, what I like is for the second table to show only one of more rows that are related to first table.

SQL SYNTAX

SELECT DISTINCT
dbo.Tb_DataPaNummer.CID, dbo.Tb_DataPaNummer.OrtID, dbo.Tb_DataPaNummer.PaNummer, dbo.Tb_DataPaNummer.GoodToKnowCom,
dbo.Tb_DataPaNummer.Station, dbo.Tb_DataPaNummer.Laptop, dbo.Tb_DataUser.UserID, dbo.Tb_DataUser.UserName
FROM dbo.Tb_DataPaNummer LEFT OUTER JOIN
dbo.Tb_DataUser ON dbo.Tb_DataPaNummer.CID = dbo.Tb_DataUser.CID
WHERE (dbo.Tb_DataPaNummer.OrtID = 2)

Please help

SELECT

e.CatID, d.CatName, e.SubID, e.SubNameFROM(SELECT a.CatID, a.CatName, c.MaxSubIDFROM CatTable1 aINNERJOIN(SELECT b.CatID,MAX(b.SubID)as MaxSubIDFROM CatSubTable1 b

GROUP

BY b.CatID) cON a.CatID= c.CatID) dINNERJOIN CatSubTable1 eON d.MaxSubID=e.SubID|||Thank you so much!!!!

No comments:

Post a Comment