开发者

need result of two table sql query

I have a two sql server tables that contains data like this

Table a

catId    |    catname          | Isdeleted
-------------------------------------------------

1               ABC开发者_高级运维               0
2               DEF               0
3               GHI               0

and another table is

Table B

id    |     Name    |    Name1      | Catid  
--------------------------------------------------
1           abc           aaaa           1 
2           def           bbbb           1 
3           ghi           gggg           2 
4           jkl           jjjj           2 
5           xyz           xxxxx          3

Now I want result in this format

catname from table a and all the fields from table b according to catid of table a and catname should be distinct.

Please help me


Write your query like this :

SELECT DISTINCT a.catname, b.* FROM a INNER JOIN b 
ON a.catid = b.catid WHERE catid = [catid]

If you have multiple records in table b for each catid or catname, you will see multiple records with same catname in result. there is no other choice unless catname be unique in both tables a and b.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜