Skip to main content
Participant
Sep 7, 2012 9:31 AM UTC
Question

SQL query syntax question

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 is closed to new replies. Start a new post to keep the conversation going.

3 replies

Inspiring
Sep 7, 2012 9:55 AM UTC

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

Translate
Participant
Sep 7, 2012 6:02 PM UTC

Thanks Adam!

Translate
Inspiring
Sep 7, 2012 9:52 AM UTC

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.

Translate