User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 423,333 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,273 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 992 | Replies: 2
Reply
Join Date: May 2008
Posts: 1
Reputation: bunary2k is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bunary2k bunary2k is offline Offline
Newbie Poster

Help - Union Select - Using VB.Net

  #1  
May 28th, 2008
i have 2 tables :
1.Ms_Menu
Menu_Id,Menu_Name
001 | Menu1
002 | Menu2
003 | Menu3

2.Tbl_User
User_Id,User_Name,Menu_Id
User1 |Name1 |001
User1 |Name2 |002
User2 |Name2 |002

i want to joined 2 tables using UNION(or other way if works is fine->left/right join)
my coding :

  1. SELECT User_Id,User_Name,Menu_Id,'' Menu_Name
  2. FROM dbo.Tbl_User
  3. UNION ALL SELECT '' User_Id,'' User_Name,Menu_Id,Menu_Name
  4. FROM dbo.Ms_Menu

THE RESULT :

User_Id,User_Name,Menu_Id,Menu_Name
User1 |Name1 |001 |Menu1
User1 |Name1 |002 |Menu2
User2 |Name2 |001 |Menu1
| |001 |Menu1
| |002 |Menu2
| |003 |Menu3

ALL I WANT THE RESULT IS :

User1 |Name1 |001 |Menu1
User1 |Name1 |002 |Menu2
| |003 |Menu3

OR

User2 |Name2 |001 |Menu1
| |002 |Menu2
| |003 |Menu3

all depend on User_Id i want to query

tq
Pa'UL
Last edited by peter_budo : Jun 15th, 2008 at 11:31 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2005
Posts: 27
Reputation: edmicman is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
edmicman's Avatar
edmicman edmicman is offline Offline
Light Poster

Re: Help - Union Select - Using VB.Net

  #2  
Jun 12th, 2008
Hmmmm, I think you want a join instead. Try something like this:

  1. SELECT User_Id,User_Name,Ms_Menu.Menu_Id,Menu_Name
  2. FROM dbo.Ms_Menu LEFT OUTER JOIN dbo.Tbl_User ON Ms_Menu.Menu_Id = Tbl_User.Menu_Id

I think that gets you close, although you might need to tweak it a bit.
Last edited by peter_budo : Jun 15th, 2008 at 11:32 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore,India
Posts: 1,270
Reputation: debasisdas is on a distinguished road 
Rep Power: 4
Solved Threads: 80
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Nearly a Posting Virtuoso

Re: Help - Union Select - Using VB.Net

  #3  
Jun 13th, 2008
when you are posting such a questiln always post what you have tried so far to solve that . That will give us an idea on your exact requirment.
Share your Knowledge.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 11:35 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC