Skip to main content
Known Participant
May 20, 2009
Question

Querying 2 tables

  • May 20, 2009
  • 2 replies
  • 785 views

Hi,

I have 2 tables "users" and "events" in one query I want to return

profilePic, firstname, surname from clients

and


eventName from events

The tables both have clientID which is passed via the URL.

This is what i have so far.

<cfquery name="qGetUser" datasource="#application.datasource#">
    
     Select profilePic, firstname, surname, eventName FROM clients, events WHERE #URL.clientID# = clients.clientID = events.clientID
     </cfquery>

Thanks

This topic has been closed for replies.

2 replies

Inspiring
May 20, 2009

This

WHERE #URL.clientID# = clients.clientID = events.clientID

should be this

WHERE clients.clientID = events.clientID
and clients.clientID = #URL.clientID#

This is very basic stuff.  If you found it tough, I have heard good things about the book Teach Yourself SQL in 10 Minutes by Ben Forta

Participating Frequently
May 20, 2009

What you want is to join the 2 tables to return a single resultset:

http://en.wikipedia.org/wiki/Join_(SQL)

http://www.w3schools.com/Sql/sql_join.asp

Mack