•
•
•
•
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
![]() |
•
•
Join Date: May 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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 :
THE RESULT :
ALL I WANT THE RESULT IS :
OR
all depend on User_Id i want to query
tq
Pa'UL
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 :
sql Syntax (Toggle Plain Text)
SELECT User_Id,User_Name,Menu_Id,'' Menu_Name FROM dbo.Tbl_User UNION ALL SELECT '' User_Id,'' User_Name,Menu_Id,Menu_Name 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
Hmmmm, I think you want a join instead. Try something like this:
I think that gets you close, although you might need to tweak it a bit.
sql Syntax (Toggle Plain Text)
SELECT User_Id,User_Name,Ms_Menu.Menu_Id,Menu_Name 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
![]() |
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- SQL String question (ASP)
- establishing connection with more than one database (VB.NET)
- three dimensional arrays (PHP)
Other Threads in the MS SQL Forum
- Previous Thread: Setting variable within an exec (@sql)
- Next Thread: SQL Syntax



Linear Mode