Odd join questing

2006-07-14 Thread Chris W

It may not be odd to many but I can't seem to think of how to do this

I have 2 queries below that give me exactly what I want each to do but 
now I want to combing them is such a way that in the second query I have 
one additional column that gives me a 1 on a row where the PID would be 
in first query and a 0 if it would not me in the first query.


so lets say for example query 1 returns the following PIDs
2,5,7,9

And the second query returns rows with the Following  PIDs
1,2,3,4,5,6,7,8,9,10.
ignoring, for now, the other columns I am selecting in the second query, 
what I want is PID followed by a column called say check such that I 
would get the following output.

| PID | Checked |
|   1 |   0 |
|   2 |   1 |
|   3 |   0 |
|   4 |   0 |
|   5 |   1 |
|   6 |   0 |
|   7 |   1 |
|   8 |   0 |
|   9 |   1 |
|  10 |   0 |

SELECT `PID` FROM serviceplanfeaturelink WHERE `SID` = '$SID'

SELECT `PID`, `psoc`, `pName` FROM product WHERE pTypeID IN 
($_FEATURES_TYPE_IDS)


Just in case your aren't familiar with PHP the $SID is just a php variable.

Any suggestions

--
Chris W
KE5GIX

Gift Giving Made Easy
Get the gifts you want  
give the gifts they want
One stop wish list for any gift, 
from anywhere, for any occasion!

http://thewishzone.com


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Odd join questing

2006-07-14 Thread Chris

Chris W wrote:

It may not be odd to many but I can't seem to think of how to do this

I have 2 queries below that give me exactly what I want each to do but 
now I want to combing them is such a way that in the second query I 
have one additional column that gives me a 1 on a row where the PID 
would be in first query and a 0 if it would not me in the first query.


so lets say for example query 1 returns the following PIDs
2,5,7,9

And the second query returns rows with the Following  PIDs
1,2,3,4,5,6,7,8,9,10.
ignoring, for now, the other columns I am selecting in the second 
query, what I want is PID followed by a column called say check such 
that I would get the following output.

| PID | Checked |
|   1 |   0 |
|   2 |   1 |
|   3 |   0 |
|   4 |   0 |
|   5 |   1 |
|   6 |   0 |
|   7 |   1 |
|   8 |   0 |
|   9 |   1 |
|  10 |   0 |

SELECT `PID` FROM serviceplanfeaturelink WHERE `SID` = '$SID'

SELECT `PID`, `psoc`, `pName` FROM product WHERE pTypeID IN 
($_FEATURES_TYPE_IDS)


Just in case your aren't familiar with PHP the $SID is just a php 
variable.


Any suggestions


Errr, I think this would work.

SELECT
   p.`PID`,
   IF(s.`PID` IS NULL, 0, 1) as `Checked`
FROM product p
LEFT JOIN  serviceplanfeaturelink s
   ON(p.`PID` = s.`PID` AND `SID` = '$SID')

Untested, but you should get the general idea if it doesn't work.

Chris





--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]