lundi 7 décembre 2015

Mkey(Unique column) column is getting repeated

I have a query which fills my gridview, but what happening here is my

mkey is getting repeated.

I dont know why

Below is my query,

SELECT  a.mkey, 0 child_menu_mkey, UPPER (a.menu_name) parent_menu, '' child_menu "+
                 "FROM wms_menu_hdr a, wms_menu_hdr b " +
                 "WHERE a.mkey = b.parent_mkey "+
                 "UNION "+
                 "SELECT DISTINCT b.mkey, b.mkey child_menu_mkey, '' parent_menu, b.menu_name child_menu "+
                 "FROM wms_menu_hdr a, wms_menu_hdr b "+
                 "WHERE a.mkey = b.parent_mkey "+
                 "ORDER BY 1, 2 

and here is what it looks like:-

enter image description here

Also see the table structure of my table wms_menu_hdr

Mkey        numeric
Sr_No   numeric
MENU_NAME       nvarchar
PARENT_MKEY     numeric
URL     nvarchar
ORDER_BY        numeric
DELETE_FLAG     char
CREATION_DATE   datetime
CREATED_BY      numeric
LAST_UPDATED_BY numeric
LAST_UPDATE_LOGIN       numeric
LAST_UPDATE_DATE        datetime

I am using SQL server 2005. I dont know why what is wrong here

Aucun commentaire:

Enregistrer un commentaire