Question: I have the following 2 tables:

Table 1

```
Organization Location
001          110 
001          112
001          113
002          119
002          121

```

Table 2

```
 UserId    Location
 User1      110
 User1      112
 User2      121

```

My parameters are Organization and UserId. Table 2 is a table that restricts access. For example, for User1, he can only see info for Location 110 and 112.
User2 can only see information for location 121. 

NOTE:
User3 which is not in table 2 can see info for all locations for a given Organization.So for example, for Organization 001 user 3 can see information for Location 110, 112, 113. Also note that any users that are not in table 2 are no restricted so we see all the locations for a given location.

How do I do a single select statement where the parameters are Organization and UserId. Based on that query I like to return the Location. I know a join is required but not sure how to construct it to accomplish the goal.

As I am entering this into a SelectCommand in ASP.NET SQLSource, I cannot use IF statement. I need to use a single select statement. I am using SQL Server for the database.

Answer: 
You erroneously were calling `System.out.println()` for the first hash mark, which was printing a newline where you don't want it. Just change that call to `System.out.print()` and you should be good to go:

```
 public class NestedLoopPattern {
     public static void main(String[] args) {
         final int HASHTAG_AMMOUNT = 6;

         for (int i=0; i < HASHTAG_AMMOUNT; i++) {
             // don't print a newline here, just print a hash
             System.out.print("#");
             for (int j=0; j < i; j++) {
                 System.out.print(" ");
             }
             System.out.println("#");
         }
     }
}

```

**Output:**

```
##
# #
#  #
#   #
#    #
#     #

```
[java8](/questions/tagged/java8 "show questions tagged 'java8'") solution:

```
IntStream.rangeClosed(1, MAX)
                .forEach(i -> IntStream.rangeClosed(1, i + 1)
                        .mapToObj(j -> j == i + 1 ? "#\n" : j == 1 ? "# " : "  ")
                        .forEach(System.out::print)
                );

```