Norbert Pisz
Norbert Pisz

Reputation: 3440

SQL Azure table relations

I have a simple database schema.

Table TAGS and table USERS.

How I can make a column in USERS table with List of TAGS ?

Upvotes: 1

Views: 125

Answers (1)

John Woo
John Woo

Reputation: 263733

It sounds that it is most likely to have Many-to-Many relationship.

Users Table

  • UserID (PK)
  • UserName
  • OtherFields...

Tags Table

  • TagID (PK)
  • TagName
  • OtherFields...

UserTagLink Table

  • UserID (FK)
  • TagID (FK)

you need to join both tables

SELECT  a.*, c.*    -- <<== select the columns you want to display
FROM    Users a
        INNER JOIN UserTagLink b
            ON a.UserID = b.UserID
        INNER JOIN Tags c
            ON b.TagID = c.TagID

To further gain more knowledge about joins, kindly visit the link below:

Upvotes: 2

Related Questions