Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2006-06-16, 03:07 PM
Junior Member
 
Join Date: Nov 2004
Posts: 13
Deus_m1k3
Exclamation select rows from 3 tables

Hi:

I need to select the rows that aren't in a specific table but with a reference to a another table the tables are:

TABLE1
clv PK
names

TABLE2
clvp PK
clv FK (from TABLE1)

TABLE3
clva PK
clvp FK (from TABLE2)
dat

I know 4 sure the dat field on TABLE3 so I need 2 select the "names" fields that aren't related with TABLE2... e.g.

TABLE1
clv names
1 X
2 XX
3 XXX

TABLE2
clvp clv
1 2
2 1
3 2
4 2
5 1

TABLE3
clva clvp dat
1 1 AT-001
2 3 AT-002
3 4 AT-001
4 2 AT-003
5 5 AT-001

I need that the query result shows:

IF dat="AT-001" THEN

names
XXX


READ YA
Deus_m1k3
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2006-06-17, 03:48 PM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

I think it is possible using a subselect where not in (query) type deal. I will mess with it some later today and see if I can get you a working query.
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #3 (permalink)  
Old 2006-06-17, 04:11 PM
Junior Member
 
Join Date: Nov 2004
Posts: 13
Deus_m1k3
Default

thanx 4 the help...

READ YA
Reply With Quote
  #4 (permalink)  
Old 2006-06-18, 04:39 AM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

Code:
select 
	table1.names
from
	table1		
where
	table1.clv not in (
		select
			table2.clv
		from
			table2,
			table3
		where
			table2.clvp = table3.clvp
			and table3.dat = 'AT-001'
	)
;
Here ya go. It is just a sub select. Now this will not work in MySQL less than 4.1.x
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #5 (permalink)  
Old 2006-06-19, 03:12 PM
Junior Member
 
Join Date: Nov 2004
Posts: 13
Deus_m1k3
Default

Sorry that didn't work, "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select table2.clv from table2, table3 where..."

READ YA
Reply With Quote
  #6 (permalink)  
Old 2006-06-19, 03:13 PM
Junior Member
 
Join Date: Nov 2004
Posts: 13
Deus_m1k3
Default

My server is a 3.23.58 version

READ YA
Reply With Quote
  #7 (permalink)  
Old 2006-06-19, 03:52 PM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

It will not work in anything less than 4.1.0 .

3.x is extremely out of date, you need to upgrade to at least 4.1.0 if not 5.x

Without upgrading, there is no way to write a query to do what you are asking. You will have to use multiple queries or other logic to filter the results.
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #8 (permalink)  
Old 2006-06-19, 05:57 PM
Junior Member
 
Join Date: Nov 2004
Posts: 13
Deus_m1k3
Default

I was just hoppin' that the upgrade could be avoided 'cos I don't have directly the control of the server but thanx 4 the tips & the big help
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.0 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.0 (a popular PHP IDE) and NuCoder 1.4 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:56 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.