Re: A mysql question...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 21 October 2010 14:13, Midhun Girish <midhungirish@xxxxxxxxx> wrote:
> | Name | phone |userid|
>
> +------------+--------------+------+
>
> | Mr Sasi | 01225 708225 | 1 |
>
> | Miss Brown | 01225 899360 | 2 |
>
> | Mr Black | 01380 724040 | 3 |
>
> +------------+--------------+------+
> Table B
>
> +------------+--------------+
>
> | blockedbyid| blockedid |
>

At first glance ...

SELECT
	A.UserID,
	A.Name,
	A.Phone
FROM
	A
WHERE
	A.UserID NOT IN
		(
		SELECT
			B.BlockedID
		FROM
			B
		WHERE
			B.BlockedByID = x
		)

The Subselect finds all the user ids blocked by x.

The main select finds all users who are NOT in the subselects list.

I'm pretty sure a subselect isn't as efficient as it could be though.



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux