Ask a Question related to Coldfusion Database Access, Design and Development.
-
weswhite7 #1
Querying data that matches in two different tables
The code is attached. Basically there are two tables, contact and recruiter.
When you initially add someone to contact, it also adds certain information to
the recruiter table along with the primary id just writen to the contact
table... confused yet? Basicaly, the attached code shows a search of the
database on form submission. I can't figure out how I get it to search the
first one and show only the ones where they are in the first db, and the second
db based on primary ids I'd assume.
Anybody have an idea?
<cfquery name="grabusers" username="sla" password="slaera" datasource="sla">
SELECT *
FROM contact
where <cfif form.firstname eq ""><cfelse>fname like
'%#form.firstname#%'</cfif><cfif form.lastname eq ""><cfelseif form.firstname
eq "">lname like '%#form.lastname#%'<cfelse>and lname like
'%#form.lastname#%'</cfif>
ORDER BY lname asc;
</cfquery>
weswhite7 Guest
-
Querying related tables
Simple query question - I have a real estate table with various fields (Beds, Baths, SqFt, etc). One of the fields is BrokerID, which is foreign... -
Querying one-to-many tables
Hi, I have a database with, for the sake of simplicity, two tables with a one-to-many relationship. The first table is the user info and the... -
querying FileMaker data
Thanks, I'll try that. -
Querying for unmatched records in two tables
I have two tables - One contains a list of all the zip codes in the US. The other table is basically a mailing list containing addresses of people... -
querying a view of a lot tables
I have setup a database to record our IP Account from ALL of our routers in a form. It's very slow and sometimes times out.. which is NO GOOD.. I... -
warddc #2
Re: Querying data that matches in two different tables
select c.*, r.*
from contact c, recruiter r
where c.id=r.id
this will return all columns joined on id. you can change the select to
return only those columns you are interested in from each table.
d.
warddc Guest
-
weswhite7 #3
Re: Querying data that matches in two different tables
ok that makes sense, the problem is im searching based on a first and last name
input. so if i put in wes, it pulls up anyone with "wes" as their name. that
comes from the contact table. so then how do i take that output and match it to
only where that id is present in teh recruiter table?
weswhite7 Guest
-
mxstu #4
Re: Querying data that matches in two different tables
Originally posted by: weswhite7
ok that makes sense, the problem is im searching based on a first and last
name input. so if i put in wes, it pulls up anyone with "wes" as their name.
that comes from the contact table. so then how do i take that output and match
it to only where that id is present in teh recruiter table?
You need to add an extra condition to the where clause provided warddc:
--- psuedo-code
select (some columns)
from contact c, recruiter r
where c.id=r.id AND
c.fName = 'Wes'
Just don't use SELECT * , as in your original post. It requires more work by
the database and usually returns more information than you actually need, which
can affect performance. It can also cause problems with your CF output, when
joining two or more tables that share some of the same column names.
mxstu Guest



Reply With Quote

