Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Suport Subquery


which mysql version supports subquery?
mysql 4.1 supports subquery?




View Complete Forum Thread with Replies

Related Forum Messages:
Client Does Not Suport
Whenever i try to connect to my database through php, it keep saying:

Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:... on line 6

I'm using Apache 2.0.52, Mysql 4.1.8 and Php 4.3.10... and win 98.

View Replies !
SUBQUERY Vs DEPENDENT SUBQUERY
I have a table called `accounts`, that contains columns:

account_name VARCHAR (128)
account_no VARCHAR (16)
account_hash VARCHAR (32)
balance DECIMAL(10,2)
There is an INDEX on account_hash and there's currently 128 rows in the table.

I have a table called `activity` that contains columns:....

View Replies !
Subquery Or Correlated Subquery Help
I need to develop a sql that uses the results from the first Query to find data in the second Query. Then the results of the second query to find the final results of the third Query. I’m also wondering if I should try to just link all these tables together instead of Subqueries or Correlated Query.

First Query
select

ACCOUNT_ID,
ACCOUNT_TYPE_C,
PAT_ID

from PAT_ACCT_CVG

where ACCOUNT_TYPE_C in (120103,120104,120101)

Second Query

SELECT

PAT_CVG_FILE_ORDER.PAT_ID,
PAT_CVG_FILE_ORDER.LINE,
COVERAGE.COVERAGE_ID,
COVERAGE.CVG_EFF_DT,
COVERAGE.CVG_TERM_DT


FROMPAT_CVG_FILE_ORDER
LEFT OUTER JOIN COVERAGE
ONCOVERAGE.COVERAGE_ID = PAT_CVG_FILE_ORDER.COVERAGE_ID


Where coverage.payor_id = ?'


Third Query

select

TRAN.ORIG_SERVICE_DATE
TRAN.TRAN_TYPE,
TRAN.INSURANCE_AMOUNT

from Tran

where TRAN.TRAN_TYPE = 1
and TRAN.INSURANCE_AMOUNT > 0
and TRAN.proc_ID in 1008,1009

(now I need to compare the dates on this query to make sure that the TRAN.ORIG_SERVICE_DATE is within the COVERAGE.CVG_EFF_DT, COVERAGE.CVG_TERM_DT ( dates of the second query)

View Replies !
Sum() And Subquery
SELECT domainTable.name as domain, sum(NetworkTraffic.upload) as Upload, sum(NetworkTraffic.download) as Download, sum(NetworkTraffic.upload) as Upload2 sum(NetworkTraffic.download) as Download2
FROM `NetworkTraffic`
LEFT JOIN domainTable ON domainTable.domainId = NetworkTraffic.domainId
WHERE NetworkTraffic.protId=2 AND date between "2005-10-11" AND "2005-10-18" GROUP BY domainTable.name

I am using the left-join above to merge two tables (NetworkTraffic and domaintable) on domainId to find which domain to present. By doing this i summarize the download and upload from NetworkTraffic between 2005-10-11 and 2005-10-18, however i want to be able to summarize the traffic from one day, say 2005-10-12 in column 3 and 4 (Download2, Upload2). Is it possible to make a subquery in the sum-function or should i take another approach? I am using mysql server 4.0.18-max-debug

View Replies !
LIKE ANY + Subquery
I'm trying to get the following statement to work:

SELECT * FROM discountItems di
WHERE di.name LIKE ANY
(SELECT lsw.word
FROM ifDefinedSearchWords dsw
join ifLinkedSearchWords lsw on lsw.fIFEntityID = dsw.fIFEntityID
WHERE dsw.word like 'schoggi')

It is supposed to find some words in a subquery as one row, and then search another table for records matching any of those words. I get the following error message:
#1064 - 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 .....

View Replies !
Subquery Help
I am using mysql 4.0 which does not support subquerys.How can i rewrite the below query using joins for mysql 4.0
select * from t1 where t1.eid not in(select eid from t2)

View Replies !
Subquery Help.
I am using the following but then I rembered I am getting the readyPrinted_id from the select statement!! How can I fix it so it gets the readyPrinted_id and then performs the AND with that same ID?

SELECT
`sub_name`
, `readyPrinted_name`
, `readyPrinted_id`
FROM sub s,
readyPrinted r
WHERE s.sub_id = $sub_id
AND s.readyPrinted_id = r.readyPrinted_id
AND r.readyPrinted_id = readyPrinted_id

View Replies !
Request Help For Subquery
I have a table that records targets and the time it appears on a
display. What I would like to do is to report the time difference for
each individual target from the initial appearance to the subsequent
one, and the time difference from the subsequent one to the next, and
so on.

So how do I put these these all together to produce one query:

for each "select distinct target from display"
for number of rows -1 with target
"select timeX - timeY from (subquery for distinct target) where
(X,Y = subsequent, initial times)"

View Replies !
How To Do A Subquery With MySQL 4.0 ?
I couldn;t upgrade to mysql 4.1 for some reason, so I am forced to use mysql 4.0.

I try to change my database from pgSQl to mySQL. But the proble is how to make a query like :

"SELECT field FROM table WHERE (select count(*) from table2)<5 "


which is very easy under pgSQL but not allowed under mysql because the subqueries seem not to be allowed...

View Replies !
Subquery (not Exists)
I've got some sort of syntax problem that doesn't seem to make a lot
of sense. I'm developing a Categories Theory application and because
of that I need to make big, and by "big" I mean HORRIBLY HUGE queries.
That one has 54 lines and 3 subqueries (only the first one is shown so
that I won't scare people off :)).

The thing is, I don't seem to be getting the hang of how to do
subqueries. The syntax seems fine... But it'll still always say the
same thing:

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 'exists ( select * from objeto c, morfismo f1, morfismo f2
(It's MySQL 4.0.11a-gamma)

The only difference I see between the code below and the mysql.com
documentation is that my subqueries aren't alone in their "where"
clauses... Aside from that, they seem pretty much okay. Am I missing
something?.....

View Replies !
Correlated Subquery
SELECT MAX(e1.score) AS high_score
, e1.dept
, (SELECT e2.emp_no
FROM Employee_Evaluations AS e2
WHERE e2.dept = e1.dept
AND e2.score = MAX(e1.score)) AS emp_no
FROM Employee_Evaluations AS e1
GROUP
BY e1.dept

It doesn't work in MySQL (I've tried 4.1 and 5.0), but it seems like it should work and if I'm not mistaken, it's valid SQL99. Can anyone confirm this? I don't need help writing a compatible version, I've already done that - just curious if this little bugger is standards compliant.

View Replies !
Slow Subquery
Can anyone tell me why the following query with sub-query takes forever to finish? (I've le it run for 20 minutes, and it still hasn't finished)

select date from temps where date in (select distinct date from observations where camera like "a")

The sub query returns 10 dates. The outer query is on a table that contains about 40,000 rows. What's the big deal here? All I'm trying to do is select rows from "temps" that match a small range of 10 dates. Is there another way to do this? Is a sub-query the wrong approach?

View Replies !
Subquery As Join
I have the following query, which works perfectly on my developpement computer:

UPDATE writings SET num_votes=(SELECT COUNT(vote) FROM votes WHERE writing_id=id), rating=(SELECT AVG(vote) FROM votes WHERE writing_id=id);

Unfortunately, my host doesn't seem to allow subqueries. Is there a way to do this with joins? I've heard that joins are faster anyhow.

View Replies !
Subquery Issue
I have a query at sql.pastebin.com/d3398502e and it's a bit of a monster (sorry, it says I can't post the actual link because I'm a new user, I assume it's a spam precaution, so please copy and paste).
It's a search query for a hotel site, like expedia, but it needs the ability to get different prices for children in a room based on their age.
Each hotel can have age groups, so it needs to figure out how many children are in each age group for that hotel (which works, that's all the UNIONs), and then apply the price associated with that age group to the number of children for that hotel for that date.
That's where I'm stuck since the price data for that date is not available in the subquery.
The way I have it now it's selecting all dates that have child prices applied and adding those together, rather than just the one date.

View Replies !
Subquery To JOIN
SQL Code:

Original
- SQL Code

SELECT
COUNT(*)
FROM `cmn_group`
AS `g`
INNER JOIN `cmn_company`
AS `c`
ON g.cmn_company_id = c.cmn_company_id
WHERE g.cmn_group_id !=5
AND g.group_name = 'G4'
AND g.cmn_company_id =
(
SELECT cmn_company_id
FROM cmn_group
WHERE cmn_group_id =5
)

 SELECT COUNT(*)FROM `cmn_group` AS `g`INNER JOIN `cmn_company` AS `c` ON g.cmn_company_id = c.cmn_company_idWHERE g.cmn_group_id !=5AND g.group_name = 'G4'AND g.cmn_company_id =( SELECT cmn_company_id FROM cmn_group WHERE cmn_group_id =5)

View Replies !
Using Limit In Subquery
I am trying to use Limit in a subquery but receive an error. Is there another way to archive the same end result without Limit?

SELECT *
FROM news
WHERE news.id NOT IN (SELECT news.id FROM news ORDER BY date DESC LIMIT 15)

Error:
#1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

View Replies !
Count With Subquery
I've a problem with a count with a 3.23.58 sql version...

Here's my sql code (short version and normal version below)...

View Replies !
Update With Subquery?
I have two tables and I want to update one with data from the other

TableA
id description date

TableB
id counter date

I want to update counter in TableB with its current value minus a count from tableA

UPDATE TableB set counter = counter - (SELECT count(id) WHERE description = 'blabla')

But I only want to do this on the date columns are equal. For example date in TableB is 2007-03-13, and counter should be updated with its value minus the selection from TableA where date is the same. But I want to do this on all rows for all dates in one query. How do I do that? Add a where to the subquery ie "WHERE TableB.date = TableA.date"? Is that correct?

View Replies !
SubQuery To Add A Column
I have the following SQL which is the best I can do to illustrate what I am trying to accomplish:

select column_name as 'name',
column_default as 'default',
column_type as 'type',
(select column_name from maillists
where listname="winserver") as 'data'
from information_schema.columns
where table_name='maillists';

Essentially, I am trying to get a "description" of my table along with an additional column of the current value for each field in the table.

What I am getting instead is a repeat of the column name in the data column....

View Replies !
Subquery In COUNT()
I have table with names and ages of peoples.
I need to select ALL names and number of younges peoples.

name|age
aaa |30
bbb |31
ccc |32
eee |32

result:
aaa |0
bbb |1
ccc |2
eee |2

I try use:
SELECT T1.name, COUNT(SELECT * FROM tablename AS T2 WHERE T2.age<T1.age) FROM tablename AS T1;

But error in syntax :(

View Replies !
Error While AVG On A Subquery
I have a ticket_audit_log table that is a list of changes done on tickets in the ticket table. Every change is a timestamp, so i can select the min and max timestamp for each ticket change and calculate the difference that is the time the ticket has been worked on.

The query I use is: ....

View Replies !
Using IN With An Empty SUBQUERY
UPDATE bb_topics SET topic_status = 1 WHERE topic_id IN (SELECT topic_id FROM bb_topics WHERE forum_id = 1 AND topic_start_time < DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND topic_status = 0);

If the subquery returns an empty dataset I get a syntax error. Is there any way to test if the subquery is null or exist. I have tried EXISTS and IFNULL with no success.

View Replies !
INNER JOIN With SubQuery
explain of INNER JOIN (SELECT .....) as alias name ON t1.ID = t2.ID with example. How the INNER JOIN consider that SELECT?

View Replies !
Subquery Using Limit
I am trying to use a limit 1 in a subquery which its returning a error saying its not supported. Basically I have a table for Locations where equipment has been and I need to run one query that returns only the last location that the equipment has been. The below query is returning any of the ID numbers where the current location = 232. This does return results but it also returns results where 232 is one of the previous locations. A simple fix would be to use LIMIT 1 in the subquery but since that isnt supported .....

View Replies !
Subquery As An Array?
Let us say I have two tables:
- user: userid, username
- post: postid, userid

In a single query, given the "userid" value, I want to select "username" from the user table, and select all postid values from the post value where the userid="myuserid".

Something like...

SELECT
username,
(SELECT postid FROM post WHERE userid="myuserid") AS postids
FROM user
WHERE userid="myuserid"

I'm sure you can spot the problem--the subquery returns more than one row of data. Is there any way I can make "postids" be an array, or a comma-separated list, or something like that?

View Replies !
Subquery With IN Clause
I have a table full of subscriptions to a service. this is our second year, and i want to see how many people returned for a new season. I am having a hard time finding a solution to this problem. so far i have this...

SELECT
count(*)
FROM product
WHERE
DATE_FORMAT(insert_date,"%Y")='2005'
AND
payer_email IN
(SELECT DISTINCT
payer_email
FROM product
WHERE DATE_FORMAT(insert_date,'%Y')='2004')

but the page just never loads when i run that. Does anyone have any ideas as to what's wrong with my query, or a better query i might make?

View Replies !
DELETE And Subquery
Here is my DELETE statement that should work but doesn't due to "Currently, you cannot delete from a table and select from the same table in a subquery. "

DELETE FROM history WHERE eventTime = (SELECT MIN(eventTime) from history)

I found information about selecting the max with a subquery here:

View Replies !
MySQL Subquery Using NOT IN
I need a little help rewriting a subquery in a MySQL db that does not support this type of query.

I have read the manual about how to convert a NOT IN to a left join and it makes good sense, but I have on small addition to it that I cannot get to work.

The manual states that this is the correct SQL for a NOT IN subquery:

View Replies !
Row Subquery In Fieldlist
I am trying to figure out how to shorten my SQL.

I know I can do this:
SELECT (SELECT some_single_field FROM somewhere) AS field_alias FROM parent_table

But I want to be able to use the subquery to return 2 values - something like this, (pseudo-code):


(SELECT some_field, some_other_field FROM somwhere) AS field_1, field_2


I know how to do comparisons in the WHERE clause using multiple columns, but I can't seem to figure it out in the beginning of the select. Does anyone know how this is done?

View Replies !
Using Union In A Subquery?
I'm trying to make a query that fetches messages that were created by one of your friends (friendships are stored in a separate table) and was thinking this query would possibly do the trick:

SELECT *
FROM public_messages
WHERE author_id IN
(
(SELECT friend_from FROM friendships WHERE friend_to=1 AND pending=0)
UNION
(SELECT from_to FROM friendships WHERE friend_from=1 AND pending=0)
)

Where the user's id is 1... Running this query gives an error of:

#1064 - 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 'UNION ( SELECT from_to FROM friendships WHERE friend_from = 1 AND pending = 0 ) ' at line 1

and of course it works fine without the union... Is such a thing possible in one query?

View Replies !
Making The Right Subquery
I've been trying to wrap my head around this one for a while, and while it would be pretty easy to do using a loop in PHP I'd like to keep it in a single SQL statement if possible.

I have a table of comments, very much like you would store comments in for a blog. It goes something like this:

idCOMMENT | FK_LIST_ID | COM_Posted | COM_Comment
autoincrement| foreign key of post | Timestamp | Text for Comment


I only want to keep the most recent 30 or so comments on each listing so I need to create a statement that will delete any excess comments.
I could loop a statement like this in PHP:
DELETE FROM COMMENT WHERE idCOMMENT IN (SELECT idCOMMENT FROM COMMENT WHERE FK_LIST_ID=(variable from PHP) ORDER BY COM_Posted Desc LIMIT 30, 10^10)

But there will be thousands of listings, (it's and that's going to be rough on the server to make thousands of calls to it each night with the maintenance script. I think there must be a way to do this in pure SQL, just send one SQL statement to the server and that's it, but can't figure it out. Can you point me in the right direction?

View Replies !
Simple Subquery
I know the basics of sql but i'm really bad at the joins and everything, so i hope someone can help me out with this.

items:

+-------+-------+
| it_id | name |
+-------+-------+
| 1 | item1 |
| 2 | item2 |
| 3 | item3 |
+-------+-------+
subitems:

+----+------+-------+
| id | name | it_id |
+----+------+-------+
| 1 | a | 1 |
| 2 | b | 1 |
| 3 | c | 1 |
| 4 | d | 1 |
+----+------+-------+
now i tried this in my php

PHP

$result = mysql_query("SELECT name FROM subitems WHERE it_id in (SELECT it_id from items WHERE name='$name'");
echo '<select name="subitems" class="list">'
while ($line = mysql_fetch_array($result , MYSQL_ASSOC)) {
   foreach ($line as $subitem) {
      echo '<option value="'.$subitem.'">'.$subitem.'</option>'
   }
}
echo '</select>'


View Replies !
Yet Another Subquery Question (I Think)
I have done some looking into subqueries on the boards and at mysql.org, but I can not seem to find the answer to my problem. Maybe there is no solution maybe the solution is simple.

I have tried to construct a query for this problem, but everytime I do I run into a problem where I don't know where to go next. So, I don't have a query that I have been trying to display....

Problem:

With MySQL 4.1.21-standard running

I have the following tables;



--
-- Table structure for table `users`
--

CREATE TABLE `users` (
`USER_ID` int(11) NOT NULL auto_increment,
`REGIONAL_ID` smallint(5) NOT NULL default &#390;',
`TEAM_LEADER_ID` smallint(5) NOT NULL default &#390;',
`username` varchar(255) NOT NULL default '',
`password` varchar(255) NOT NULL default '',
`access_level` smallint(2) NOT NULL default &#390;',
`status` tinyint(1) NOT NULL default &#391;',
`num_logins` int(11) NOT NULL default &#390;',
`type` smallint(2) NOT NULL default &#390;',
`last_accessed` bigint(20) NOT NULL default &#390;',
`last_modified` bigint(20) NOT NULL default &#390;',
`created` bigint(20) NOT NULL default &#390;',
PRIMARY KEY (`USER_ID`),
UNIQUE KEY `username` (`username`)
) ENGINE=MyISAM AUTO_INCREMENT=464 DEFAULT CHARSET=latin1 AUTO_INCREMENT=464 ;

--
-- Table structure for table `profile_core`
--

CREATE TABLE `profile_core` (
`STUDENT_ID` int(11) NOT NULL auto_increment,
`AGENT_ID` int(11) NOT NULL default &#390;',
`SUPERVISOR_USER_ID` int(11) NOT NULL default &#390;',
`HOST_ID` int(11) NOT NULL default &#390;',
`SCHOOL_ID` int(11) NOT NULL default &#390;',
`type` enum('Normal','Tuition','Hidden','Pals','Private','Cancelled') NOT NULL default 'Normal',
`student_number` varchar(6) NOT NULL default &#390;',
`first_name` varchar(255) NOT NULL default '',
`last_name` varchar(255) NOT NULL default '',
`city` varchar(255) NOT NULL default '',
`nationality` char(2) NOT NULL default '',
`gender` char(1) NOT NULL default '',
`birthdate` bigint(20) NOT NULL default &#390;',
`is_esl` enum('true','false') NOT NULL default 'false',
`may_pay_tuition` enum('No','Yes') NOT NULL default 'No',
`archived` char(1) NOT NULL default &#390;',
`archived_date` bigint(20) NOT NULL default &#390;',
`comments` text NOT NULL,
`last_modified` bigint(20) NOT NULL default &#390;',
PRIMARY KEY (`STUDENT_ID`),
UNIQUE KEY `student_number` (`student_number`)
) ENGINE=MyISAM AUTO_INCREMENT=1442 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1442 ;
There are a couple of types of users that you can pull from the users table. Regional Managers, State Managers and Area Coordinators are the ones I am mostly trying to get at.

Every Area Coordinator has a State Manager and a Regional Manager identified by TEAM_LEADER_ID, AND REGIONAL_ID in the `users` table. Every State Manager has a Regional Manager (REGIONAL_ID).

Every Student has a SUPERVISOR_USER_ID identified in the 'profile_core' table which is a direct relation to the USER_ID of the `users` table.

What I want to do is find all of the students that are under a user. It is easy, for me, when we talk about only seeing students that are under a Area Coordinator:



SELECT
STUDENT_ID,
CONCAT(CORE.first_name, ' ', CORE.last_name) AS StudentName
FROM
`profile_core` AS CORE
LEFT
JOIN `users` AS USERS
ON CORE.SUPERVISOR_USER_ID = USERS.USER_ID
WHERE USERS.USER_ID = 1
My problem comes when I want to pull up all of the students that are under a Regional (including all of the students that are under all of the Regionals State Managers and all of the students that are under the State Managers Area Coordinators). I hope that made sense.

Is it possible in one query? Or, will it take two?



View Replies !
Subquery Problem(s)
I have set up a database (MySql 4.1.21) with these tables and rows:

players
p_id (= player_salary.players_id)
team_id
div_id
conf_id
fname
lname
position
status

player_salary [1 to many]
player_id (= players.p_id)
yr
amount
type

Basically, the “players” table holds some information for multiple players, and the “player_salary” table holds a player’s salary for each year of their contract.

What I am trying to do is display the players’ names and their total salary across the length of their contracts. So, I decided to throw all the relevant player data from the database into a multidimensional array, and then output it with PHP (5.1.6).

Here’s my query and

PHP

$query = array();

$query[] = 'SELECT DISTINCT *  ' FROM players, player_salary, (SELECT SUM( amount ) AS salary_total FROM player_salary GROUP BY player_salary.player_id) AS table01  GROUP BY players . p_id  ORDER BY players . lname ASC'

$rowSet = array();
for ($i = 0; $i < count($query); $i++) {
    $result = mysql_query($query[$i],$link) or die(mysql_error());
    while ($row = mysql_fetch_assoc($result)) {
        $rowSet[] = $row;
    }
    mysql_free_result($result);
}

echo '<table>'

foreach ($rowSet as $outer_key=>$single_array){
echo '<tr>'
    echo '<td>'.$rowSet[$outer_key]['lname']. ', '.$rowSet[$outer_key]['fname'].'</td>'
    echo '<td>'.$rowSet[$outer_key]['salary_total'].'</td>'
echo '</tr>'
}
echo '</table>'



And here’s where the problems start. While I can calculate the total salary for Johnny Doe, for some reason that same amount appears for John Doe as well (same with the values for ‘year’ and ‘amount’ ). In reality Johnny Doe’s total salary should be (5,000,000+3,000,000+3,000,000=11,000,000) and John Doe’s salary should be (2,000,000) 2,000,000.

Here’s what the array looks like:



Array
(
[0] => Array
(
[p_id] => 1
[team_id] => 14
[div_id] => 2
[conf_id] => 1
[fname] => John
[lname] => Doe
[position] => F
[status] => active
[player_id] => 0
[yr] => 2007
[amount] => 5000000
[type] =>
[salary_total] => 11000000
)

[1] => Array
(
[p_id] => 0
[team_id] => 14
[div_id] => 2
[conf_id] => 1
[fname] => Johnny
[lname] => Doe
[position] => F
[status] => active
[player_id] => 0
[yr] => 2007
[amount] => 5000000
[type] =>
[salary_total] => 11000000
)

)

So, I’m wondering if someone can tell me what I’m doing wrong?

I’m pretty sure it’s the query because when I try the subquery (SELECT SUM( amount ) AS salary_total FROM player_salary GROUP BY player_salary.player_id) in phpMyAdmin, it works. When I put it all together I get the aforementioned results.

View Replies !
Subquery Error
I'm receiving this error:

Quote:

This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

Not sure why, I'm running MySQL Version 5.0.41-community-nt with WAMP5.

Any suggestions? It's a personal project that I would like to continue developing on localhost.

View Replies !
Need Help With Subquery Syntax
First, what I want to do:
I want records from table1, but only the ones that have a "yes" in columnX in table2 for the same memberID (foreign key).

I have two tables:

ind1b (indID, memberID, date, ...) and
reports (reportID, memberID, okay, date)

To select all rows in table ind1b I have this query:

$query = "SELECT * FROM ind1b WHERE memberID = '$memberID' ORDER BY datum ASC".
But I also need to check in table reports to see if there is a "yes" in column "okay" for the variable $memberID. Multiple rows (with different dates) can be returned.

So I added this subquery:

$query = "SELECT * FROM ind1b WHERE memberID = '$memberID' IN (SELECT reports.okay FROM reports WHERE reports.okay = 'Yes')
ORDER BY ind1b.date ASC";
This query gives no error run through phpMyAdmin – but also returns no records. I think that I need the "date" in there somehow but can't figure out how and where.

View Replies !
Subquery And Counting
I have a table called people in my database.

it looks like this

+----+------+
| id | name |
+----+------+
| 2 | bob |
| 1 | Jill |
| 3 | Jill |
| 4 | John |
| 5 | Jill |
+----+------+
I want to display the distinct name and how many times they are in the table
So like this

Jill - 3
bob - 1
John - 1

How would I go about doing this. I thought maybe something like this but not to sure

[code]
SELECT COUNT(name)
FROM people
WHERE name =
(SELECT DISTINCT name
FROM people);
[code]

View Replies !
Alias And Subquery
This seems simple, but I can't quite get it. Says that allocation_sum in the last line is an unknown column.

SELECT payments.*,
(SELECT sum(allocations.amount) FROM allocations WHERE payments.id = allocations.payment_id) as allocation_sum
FROM payments
WHERE payments.amount <> allocation_sum;

View Replies !
How To Rewrite This Query Without A Subquery ?
For speed reasons, I would like to rewrite the following query without the subquery: ...

View Replies !
Convert Subquery To JOIN
I have a working subquery:Code:

SELECT ID, company_name, logo_file_name FROM company ORDER BY (SELECT 1 FROM company as inside WHERE TRIM(logo_file_name) != '' AND ID = company.ID) DESC, company_name ASC

It grabs all of the company rows, and puts the ones that have a logo file name at the top.This query works fine on my testing machine (mysql 4.1.7).
However, my production machine only has mysql 4.0.18 and I have no way of upgrading it to 4.1 to get subquery support. I've been looking at trying to convert it using a JOIN statement, but I'm stumped.

View Replies !
Subquery With Delete Statement
Can we use subquery with Delete statement, when I execute the following Delete statement, I'm getting error msg.

DELTE imprs_rep_access FROM imprs_rep_access WHERE access_rep_id IN (SELECT * FROM imprs_rep_access ra WHERE ra.access_url ='/' AND ra.access_rep_id NOT IN
(SELECT min(ra.access_rep_id) FROM imprs_Rep_access ra WHERE ra.access_url='/' GROUP BY ra.session_id))

Error Msg: ERROR 1093 (HY000): You can't specify target table 'imprs_rep_access' for update
in FROM clause

View Replies !
Subquery Syntax Error
Code:

INSERT INTO library (tape_id,number) VALUES('DDFA3','433145')
WHERE DDFA3 NOT IN (select tape_id from library where used = '1')";
I'm basically wanting to make sure that no record for that tape_id exists that is set to "used" before I insert another record.

View Replies !
Subquery In The SELECT Clause
I am having the problem in the sql statement

SELECT name,
(SELECT Sum(xxx) FROM myTable GROUP BY fld) as mySum ,
(mySum + 1)/2 as myVal
FROM myTable1

This resulted in an error!!
How can i use the 'mySum' in this query

View Replies !
Syntax Error On Subquery
i am running this query
PHP Code:

 update utest set utest_score = (select count from uanswer, answer where uanswer_utest_id = 24 and uanswer_answer_id = answer_id and answer_correct = 1 ) where utest_id = 24

both queries work seperately but it is not working in this pattern, what could be wrong?

View Replies !
Using A Subquery Field In The WHERE Clause
How can use a field like "description" in the WHERE clause? ......

View Replies !
INSERT INTO (subquery) Problem
I have a very simple table (index,filename,pixelsize) and I want to Insert data for pixelsize for each filename that matches a pattern. I was thinking of
INSERT INTO (SELECT `pixelsize` from `filelist` WHERE `filename` LIKE 'L8%') VALUES ('16.888' );

the select statement works on it own but not in combination. Dunno whats wrong any suggestions?

Btw. the table looks like this:

CREATE TABLE `filelist` (
`index` SMALLINT NOT NULL AUTO_INCREMENT,
`filename` LONGTEXT,
`pixelsize` LONGTEXT,
PRIMARY KEY ( `index` )
)

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved