By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,334 Members | 2,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,334 IT Pros & Developers. It's quick & easy.

Mysql Select query with php

P: n/a
Hi, I want to create a sql query but don't know if this is possible with
mysql.
The Query should do the following:
Select all db entries from table in which entry a is smaller than the number
(count) of all db entries with criteria x from another table.
Thx for your help!
Benjamin Dickgießer
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sun, 16 Nov 2003 12:08:19 -0000, "Benjamin Dickgießer"
<Be******@dickgiesser.net> wrote:
Hi, I want to create a sql query but don't know if this is possible with
mysql.
Please don't multipost, you've sent an identical post to alt.php.sql. If you
want to post to multiple groups, then crosspost (one message, with multiple
groups in the Newsgroup header).
The Query should do the following:
Select all db entries from table in which entry a is smaller than the number
(count) of all db entries with criteria x from another table.


In most databases, you'd just use a subquery:

SELECT *
FROM table2
WHERE a < (SELECT COUNT(*)
FROM table1
WHERE 'criteria x')

But MySQL doesn't support subqueries.

So you're probably better off executing the subquery to get the count, and
then doing a second query against the first table to compare with entry 'a'.
Assuming that your 'criteria x' is independent of the outer select, though.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #2

P: n/a
4.1 does.
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:7i********************************@4ax.com...
On Sun, 16 Nov 2003 12:08:19 -0000, "Benjamin Dickgießer"
<Be******@dickgiesser.net> wrote:
Hi, I want to create a sql query but don't know if this is possible with
mysql.
Please don't multipost, you've sent an identical post to alt.php.sql. If

you want to post to multiple groups, then crosspost (one message, with multiple groups in the Newsgroup header).
The Query should do the following:
Select all db entries from table in which entry a is smaller than the number(count) of all db entries with criteria x from another table.
In most databases, you'd just use a subquery:

SELECT *
FROM table2
WHERE a < (SELECT COUNT(*)
FROM table1
WHERE 'criteria x')

But MySQL doesn't support subqueries.

So you're probably better off executing the subquery to get the count,

and then doing a second query against the first table to compare with entry 'a'. Assuming that your 'criteria x' is independent of the outer select, though.
--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

Jul 17 '05 #3

P: n/a

On Sun, 16 Nov 2003 16:15:01 GMT, "john" <my******@john.com> wrote:
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:7i********************************@4ax.com.. .

But MySQL doesn't support subqueries.


4.1 does.


4.1 is still alpha; when it's released, then it'll be fair to say MySQL
supports subqueries.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.