Skip to main content
Participant
September 7, 2012
Question

SQL query syntax question

  • September 7, 2012
  • 2 replies
  • 1059 views

I am looking at the following query and I have a couple of questions about it.

I understand basic SQL syntax but I am not understanding some parts of the following query.

<cfquery name="GetPossibleUsers" datasource="bc">

                    SELECT   uid, fname, lname

                    FROM     UserInfo UI

                    WHERE    uid IN (SELECT uid

                                                       FROM   UserCampDates

                                                       WHERE  CampDateID = #q_CampID#)

                    ORDER BY lname ASC

</cfquery>

1. Where it says "FROM     UserInfo UI" I understand that "FROM UserInfo"  would mean from the UserInfo table but I don't get the "UI" part. What would the UI part represent?

2. I presume the part:

WHERE    uid IN (SELECT uid

      FROM   UserCampDates

      WHERE  CampDateID = #q_CampID#)

is a kind of compound query (if that is the right terminology) This seems pretty useful but I have not used this method. What would this be called?

This topic has been closed for replies.

2 replies

Inspiring
September 7, 2012

1. Where it says "FROM     UserInfo UI" I understand that "FROM UserInfo"  would mean from the UserInfo table but I don't get the "UI" part. What would the UI part represent?

It's an alias for the table.  It's pointless in this particular query, because neither the table nor the alias are referenced anywhere else.

http://www.w3schools.com/sql/sql_alias.asp

2. I presume the part:

WHERE    uid IN (SELECT uid

      FROM   UserCampDates

      WHERE  CampDateID = #q_CampID#)

is a kind of compound query (if that is the right terminology) This seems pretty useful but I have not used this method. What would this be called?

It's called a "subquery": http://en.wikipedia.org/wiki/Subquery#Subqueries

--

Adam

Participant
September 7, 2012

Thanks Adam!

Inspiring
September 7, 2012

Question 1 - UI is an alias for UserInfo.  It has the potential to save typing, but that doesn't happen in this example.

Question 2 - it's called a subquery.