Microsoft
Software
Hardware
Network
Question : SQL Query [Multitables] in DataGridView
I am trying to execute SQL Query to get data from two tables, here is example:
Table1: Users { id, Username, GroupID }
Table 2: Groups { id, GroupName }
SQL Query: SELECT Users.Username,Groups.Grou
pName FROM Users,Groups WHERE Users.GroupID = Groups.id
This will show the columns Username and GroupName in data grid, this way will find group name for each group id, so the user will see the group name not the group id.
The Result in DataGridView
--------------------------
----------
----------
--
Username GroupName
--------------------------
----------
----------
--
User1 GroupA
User2 GroupA
User3 GroupB
User4
In the above example User4 don't have group, in the table Users it have the Username: User4, GroupID: 0, The group id which is ZERO is not existed, so there is not group name available for User4.
The problem is if the user group id is not existed in "Groups" table the row will not appear in the result.
I want all the data to appear, if the group is not existed for the user id, it appear blank.
Answer : SQL Query [Multitables] in DataGridView
SELECT Users.Username,Groups.Grou
pName
FROM Users LEFT JOIN Groups ON Users.GroupID = Groups.id
Random Solutions
Folders UNIDs and Duplicates
I want to put a small instruction in the middle of my SharePoint survey. I want to say "If you answered "No" to any of the questions above then please answer the questions below. How?
OpenOffice 3.2 GPO Install Problem
Microsoft Exchange Outlook Anywhere SSL Issue
Terminal server 2008 R2 Pinned Taskbar Links
Automatically Adding Text to Cells
Registry, Winlogon, KEY_WOW64_64KEY errors
Multiple Links onto one big graphic
How to stablish a proper setup in MS Outlook 2003 encrypting mails
Exchange 2010 Mailbox Role Installation Error