ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old November 3rd, 2004, 07:39 AM
stockwet stockwet is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 6 stockwet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Coldfusion/MySQL Query Help

Hi everyone, I'm having a bit of trouble coming up with the right approach to a problem. I think it can be solved using a query, but I may have to resource to some custom functions, I don't know.

First, I'm using MySQL. Let's say I have two tables:
Table 1
A
B
C
D

Table 2
A | 1
A | 3
B | 2
C | 1

I want to first get all the values out of table one and then somehow flag the values in table one that are also included in table 2 where the second column in table 2 is equal to "1". The resulting table migh look something like this:
Table 3
A | Flag
B
C | Flag
D

Any ideas about the best way to handle this using MySql?

Reply With Quote
  #2  
Old November 3rd, 2004, 08:11 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
You probably want to ask this in the MySQL forum.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old November 3rd, 2004, 09:02 AM
stockwet stockwet is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 6 stockwet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks.

I thought about that, but I'm not sure this is a MySQL solution. What I really think has to happen is that I need to have two queries, one for each table. Then I need to convert one to a struct and loop through the other to add a flag to the struct. I'm not sure what the right approach is.

Reply With Quote
  #4  
Old November 3rd, 2004, 09:29 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
No, this doesn't have anything do do with CF. It sounds like you want to join the tables together, this is standard SQL. Something like:

select t1.theAorBcolumn
from table1 t1,
table2 t2
where t1.theAorBcolumn = t2.theAorBcolumn
and t2.the1or2column = 1

Reply With Quote
  #5  
Old November 3rd, 2004, 11:27 AM
stockwet stockwet is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 6 stockwet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by kiteless
No, this doesn't have anything do do with CF. It sounds like you want to join the tables together, this is standard SQL. Something like:

select t1.theAorBcolumn
from table1 t1,
table2 t2
where t1.theAorBcolumn = t2.theAorBcolumn
and t2.the1or2column = 1


Actually, this is a little more than that. If I used your method, I would only get records between the two tables where the value = 1. That's not what I want. I want all the records in table 1 and then I want to flag the records in table 1 where a) the record exists in table 2 AND b) field 2 in table two is equal to 1. A simple left join doesn't work either. Here's an example:

Select * from Table1
Left Join Table2
ON Table1.Col1 = Table2.Col1

The results would look like the following:
Table1.col1 | Tbl2.col1 | Tbl2.col2
A | A | 1
A | A | 3
B | B |2
C | C | 1
D |D | Null

An inner join would do the same, but it wouldn't include D because there is no D value linked in Table 2.

Again, that's not what I want. I want something that tells me that in table 2, A and C are linked with value "1" and I don't care about everything else:
A | Yes
B | No
C | Yes
D | No

No duplicates and the data is filtered or flagged based on a data value I'm looking for. If there's a standard SQL query for this, I'm happy to try it.

Reply With Quote
  #6  
Old November 3rd, 2004, 12:56 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
You want an OUTER JOIN as you're showing in this example. You should just be able to add additional WHERE clause elements to limit which ones have 1 in the second table. Or it could get more complex and you'll need an inline view and/or conditional logic like case statements in the SELECT clause. Any way you do it, it's definitely a SQL issue, so like I said you may want to post in the MySQL forum which is specifically for this sort of thing.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Coldfusion/MySQL Query Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway