• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

19. Some Common Data Manipulation Proble... > 19.4. Making Assignments with Defaul...

Making Assignments with Default

Imagine a conference where your task is assigning conference rooms to attendees. Table 19-7 shows the preregistered attendees along with corresponding room numbers.

Table 19-7. Assignment table

Name

Room

_default

15

_default

14

_default

13

_default

12

Bach

123

Beethoven

231

Mozart

455

Chopin

455

Elgar

231

Gluck

123

Liszt

455

Note that the table contains several default choices. If an individual is not in the table, then you want to assign one of the default rooms to that individual. Moreover, to avoid overcrowding, you want to assign the default room numbers randomly. How do you do this?

Solution

This problem can be solved in a variety of ways, one of which provides a nice use of both subqueries and the UNION statement. First, consider the SQL statement:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint