Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Databasing
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 09-19-2009, 10:37 PM
  #1
Sawtooth500
Lord (Level 16)
 
Sawtooth500's Avatar
 
Join Date: Nov 2007
Location: Chicago, IL. USA
Posts: 574
iTrader: (0)
Sawtooth500 is on a distinguished road
Need help writing a query

Alright so I'm dealing with two mysql tables here:

This is property_table


This is table dupe_relationships


Now, in property_table, each entry has a unique propid, which is auto-increment. Table dupe_relationships has 2 columns. We start our problem here with a known propid. Now, that propid may exist in dupe_relationships either in the propid1 column or propid2 column (FYI the same propid cannot exist in the same row in both the propid1 and propid2 columns). Whether our specified propid is in propid1 or propid2, the other column in the same row will have a different correlating propid. In some cases there may be multiple maches, in others none.

So what I need is a query in which you specify a propid, then it searches for that propid in both columns propid1 and propid2 within dupe_relationships, pulls out the correlating propid whenever a match is found, and the returns certain values from property_table in rows where that correlating propid is the primary key.

I hope that I've been clear enough in what I'm trying to do here. I know if I can get a query to do this it will be way simpler than having php do all the sorting manually. I just have no clue about how to write a query that complex! Thank you for the help!
__________________
-Taras Hryniw

http://www.waltonstreetwebdesign.com
Sawtooth500 is online now   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-20-2009, 03:30 PM
  #2
Vege
Super Deity (Level 18)
 
Join Date: Sep 2004
Location: Finland
Posts: 3,410
iTrader: (0)
Vege is just really niceVege is just really niceVege is just really niceVege is just really nice
Code:
select * from property_table where propid in(select propid1 from dupe_relationships where propid2='searchstring' union select propid2 from dupe_relationships where propid1 = 'searchstring')
Will that do?
Vege is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-20-2009, 04:07 PM
  #3
Sawtooth500
Lord (Level 16)
 
Sawtooth500's Avatar
 
Join Date: Nov 2007
Location: Chicago, IL. USA
Posts: 574
iTrader: (0)
Sawtooth500 is on a distinguished road
Vege, thanks a bunch, you just saved me a ton of time of trying to do the sorting in PHP with multiple queries, actually however one thing that I forgot to specify in my original request, the query returns a set that matches those certain conditions. I actually need a set returned of all the values in property_tables EXCEPT the value that match those conditions which were obtained from dupe_relationships. Thanks!
__________________
-Taras Hryniw

http://www.waltonstreetwebdesign.com
Sawtooth500 is online now   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-20-2009, 11:47 PM
  #4
Sawtooth500
Lord (Level 16)
 
Sawtooth500's Avatar
 
Join Date: Nov 2007
Location: Chicago, IL. USA
Posts: 574
iTrader: (0)
Sawtooth500 is on a distinguished road
Figured it out, I just discovered the "not" keyword thank you again for the help vege!
__________________
-Taras Hryniw

http://www.waltonstreetwebdesign.com
Sawtooth500 is online now   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  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
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 03:41 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.