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




Using CONCAT In Subqueries


SELECT tblmonths.fldMonth, tblyears.fldYear, tblmonths.fldID, CONCAT(tblmonths.fldID," ", tblyears.fldYear)
FROM tblmonths, tblyears
where CONCAT(tblmonths.fldID," ", tblyears.fldYear)
NOT EXISTS
(SELECT CONCAT(fldMonth, " ", fldYear)
from tblexpensesclaims)
GROUP BY tblyears.fldYear, tblmonths.fldID




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Concat Maybe?
Theres a way in mysql to get a comma separated list of fields in a one to many relationship - rather than multiple rows for each record in the 'one' table. But I can't remember what it is, I thought it was concat but that didn't work... I've done it before but I can't remember what it was or why.

Using CONCAT
Is it possible to make query which would select some value even column would be NULL/EMPTY ?

Example:

Table
name

John
NULL
Mike

SELECT CONCAT_WS('something',name) FROM table;

results:
Johh
Something
Mike

WHERE With CONCAT
I have a table A with a (varchar 20) A.field and a table B with two (varchar 10) fields: B.field1 and B.field2.

How can I make a SELECT with a WHERE of this type:

WHERE A.field = CONCAT (B.field1 , B.field2)

I get an error in CONCAT. How is the string concatenation in mySQL?

Concat
I'm trying to combine 2 fields into 1 new field using concat. This is what I using

UPDATE 'idxactrs' SET 'idxactrs.desc' = concat(remarks1,remarks2)

It just says "You have an error in your SQL syntax near ''idxactrs' ...

Any Ideas?

Using Concat()
I'm trying to combine 2 fields into 1 new field using concat. This is what I using

UPDATE 'idxactrs' SET 'idxactrs.desc' = concat(remarks1,remarks2)

It just says "You have an error in your SQL syntax near ''idxactrs' ...

Use CONCAT
I'm having lots of problems using the CONCAT instruction. I'm trying to store in a variable (@f) a COUNT, but the system always crashes and I don't know why. Here you have the lines:


set f=0;
set @f:=f;
set @stmt3:=CONCAT("select count(*) into `",@f,"` from `",@n,"` where sourceurl=`",@b,"` and link=`",@c,"`");
prepare query from @stmt3;
execute query;

Concat
I'm having problem using concat

select CONCAT(firstname,' ', lastname) as fullname from tbltable where fullname = 'name';

It say Unknown column 'fullname' in 'where clause'. It is my sql wrong or what?

How To Use CONCAT In The 'FROM' Section
For example I'd like to use the following query:
SELECT * FROM CONCAT('table_', 'name');

Is there a way to do this? or something similar?


How Does Mysql_field_len Act On CONCAT?
I am quite puzzled by this. I have two fields which if selected by themselves will return a field length of 2 using mysql_field_len. However if I select them as CONCAT(field1,' ',field2), the field length is much greater than the 5 I would expect. It looks to be about 20. Is there a way to control this length? Where is it getting the field length from?

EDIT: Nevermind, this can be done using CAST(CONCAT(field1,' ',field2) AS CHAR(5))

Concat Two Tables
I have two tables, one containing payments to a supplier and one containing
invoices issued by a supplier. I'd like to get a total from each table with
one query.

I need somehow to list all payments and all transactions together in one
table result set.

i.e.....

CONCAT And Variables
I have the following statement:

------------------
SELECT CONCAT('hxxp://www.whatever.com/all.html?t=4&p=1&u=',@c) into @c;

set @stmt3:=CONCAT("INSERT INTO webs values ('",@c,"')");
prepare query from @stmt3;
execute query;
--------------

I think that I'm using correctly the CONCAT function but it doesn't work.

CONCAT Function (bug?)
I'm needed to insert large BLOBs into a database. With the 1MB packet
limit, sending larger amounts of data would be difficult, so I had a neat
idea. I would do an initial insert of an empty record and get the
auto_insert ID from the response, and then loop through, appending data to
the record.

My table is simple. One unsigned int auto_increment field (DataID), and
one long blob field (BinaryData).

When I loop through the data to send, I run:

UPDATE BinaryTable SET BinaryData=CONCAT(BinaryData, 'My binary data
here') WHERE DataID = 35


The binary data I insert I escape null characters, backslashes, single and
double quotes. The data seems to insert fine.

The problem is that as I increase the amount of data in the field, CONCAT
seems to drop all but the last 416k of the data. Thus if I loop through
adding 400k blocks at a time (Which I do) I am left with at most 800k of
data in the blob field.

Using 4k blocks I end up with 419k of data in the field when all is said
and done.

Update Using Concat
I have a form that I call for the data from a database table. Once the table is filled with data, the viewer has the option to add data to one field in the form. I want to be able to add the new comments without losing the old comments in the db column.

Field A has the existing data ($Remarks)
Field B has the new comments ($NRemarks)

I have tried various CONCAT statements but none of them work, and I am thinking that this may be because Field B is not a column in the DB, as it is new information being added.

Is there a way to keep the data in the DB column called Remarks and add the information in Field B to it on a seperate line.

I don't know if there is a command like append or edit or add to, that will add information to the existing information. I have tried the following:

$sql="UPDATE 'workorder' SET Remarks CONCAT (Remarks, NRemarks)";
?>

$sql="UPDATE 'workorder' SET Remarks CONCAT ($Remarks, $NRemarks)FROM workorder WHERE Work = '$Contact'";
?>

$sql="UPDATE `workorder` SET Remarks = CONCAT(SELECT Remarks FROM workorder
WHERE Work = '$Contact', '', '$NRemarks') WHERE Work = '$Contact'";
?>

Using CONCAT For 2 Tables
Currently I'm using this SQL query to connect 2 tables but now, I need to add a 3rd table in the same manner as the "links" table in the following query.

SELECT * FROM tracker LEFT JOIN links ON tracker.location = CONCAT('link[', links.linkid, ']') ORDER BY tracker.occurred DESC LIMIT 0, 15

Problem With Concat
I have the following select:

SELECT distinct name, main.ACCOUNT,
concat(FlatNo,' , ',FlatName,' , ',number,' , ',`St Name`,' , ',SuburbName,' , ',`Town Name`,' , ',Stand) AS Address
FROM ...

I need to return all the available address information that we have but the select returns only about 15 addresses in a DB of about 100000. Some of the address fields do contain null values and the SELECT CONCAT is returning null for the whole row if any field contains a null value.

Is there anyway round this? I have tried IFNULL(Field,"") inside the concat but this does not seem to work either.

CONCAT Function
I'm needed to insert large BLOBs into a database. With the 1MB packet
limit, sending larger amounts of data would be difficult, so I had a neat
idea. I would do an initial insert of an empty record and get the
auto_insert ID from the response, and then loop through, appending data to
the record.

My table is simple. One unsigned int auto_increment field (DataID), and
one long blob field (BinaryData).

When I loop through the data to send, I run:

UPDATE BinaryTable SET BinaryData=CONCAT(BinaryData, 'My binary data
here') WHERE DataID = 35


The binary data I insert I escape null characters, backslashes, single and
double quotes. The data seems to insert fine.

The problem is that as I increase the amount of data in the field, CONCAT
seems to drop all but the last 416k of the data. Thus if I loop through
adding 400k blocks at a time (Which I do) I am left with at most 800k of
data in the blob field.

Using 4k blocks I end up with 419k of data in the field when all is said
and done.

Please let me know if/when this will be fixed, and if there is a
work around that might be used, r a better way to insert BLOB data is
known.

CONCAT All Columns
I want to produce a query that does something like this:

SELECT MD5(CONCAT(*)) FROM table WHERE 1

* is all the columns.
I don't want to have to type in every column name, but have MySQL do it.

Problems With Concat
I'm having problems with Concat. I have this piece of code:

set @m:=a;
SET @stmt1:=CONCAT("INSERT INTO ",@m," VALUES (b,c)");
PREPARE query from @stmt1;
execute query;

b and c are cursors and when it tries to execute the query and I get the following error:

"Unknown column 'b' in field list"


It seems that is not doing correctly the CONCAT?

Concat For Numbers
I am interested in performing a concat for numbers with a space
e.g.
select concat (num1, ' ', num2) from tablex as numconc

such that if num1 is 123 and num2 is 456 the result would be '123 456'
I believe concat should work for a string rather than number format, however having created the fields num1 and num2 in string format it still does not work.
Any advice on why this isn't working, or an alternative method to achieve the result would be most welcome.


Help With Subquery / Group Concat
I've attached some data from which I want to extract individual itinerary ids and show the ships which go to those destinations. The problem is that the destination ids are stored as comma separated values in a single field and there are rows which duplicate the same associations between the ship and destination ids. I can do:

SELECT ship_id, GROUP_CONCAT(DISTINCT destination_ids) FROM itineries GROUP BY ship_id;

and get a list of destination ids for each ship but what I actually want is a list of ships for each destination Id.

Can somebody give me some pointers on how to achieve this? I think it might be possible with a subquery but am not sure how to go about this. MYSQL version is 4.1.20.

SELECT CONCAT() Subquery
SELECT * FROM
(SELECT CONCAT(comments.category,'s') FROM comments WHERE comments.author_user_id = '1')

The subquery alone yields "post" (`comments.category` is an ENUM() field); and I want to select all the rows from the "posts" database table. Ideally, the query would be processed like:

SELECT * FROM posts

How do I perform a string concatenation during a SELECT query?

SELECT Subquery CONCAT
SELECT * FROM
(SELECT CONCAT(comments.category,'s') FROM comments WHERE comments.author_user_id = '1')

The subquery alone yields "post" (`comments.category` is an ENUM() field); and I want to select all the rows from the "posts" database table. Ideally, the query would be processed like:

SELECT * FROM posts

How do I perform a string concatenation during a SELECT query with MySQL?

CONCAT () Returns BLOB
MySQL ver. 3.23.49

SELECT tblHrsClass.classid , CONCAT( tblHrsClass.classTtl ,' ', tblHrsClass.classDate ) class_ttl FROM tblHrsStudent LEFT JOIN tblHrsClass ON tblHrsStudent . classid =tblHrsClass.classid GROUP BY tblHrsClass . classid HAVING COUNT(tblHrsStudent . classid )<19

The query above is broke. I'm using it to build a list box.

I can run the query without the CONCAT function and pulls the expected data.

When I add CONCAT( tblHrsClass.classTtl ,' ', tblHrsClass.classDate ) class_ttl,

class_ttl is returned as a BLOB of a certain size.

Need To Concat Column And DATE_FORMAT
I'd like to combine the title and starttime so I can distinguish amongst several requests with the same title. ie:

ID=7116
name=Testing11-26-2007

Here's my query:
select ID, title+DATE_FORMAT(starttime,"%m-%d-%Y") as name from requests where ID=7116

Which gives me:
ID=7116
name=11

What do I need to do to get the result of DATE_FORMAT into a form that will concat with the text from another column?

Concat 2nd Table Results Into First?
Given three tables used to track multiple email addresses and phone numbers for a person:

Table 1: id, name, address
Table 2: table1_id, email
Table 3: table1_id, phone

How can I do a select to end up with all emails and phones concated together into a single row per individual:

id, name, address, "email,email,email", "phone,phone"

The solution needs to work with MySQL 3.23 (or possible MySQL 4.0). 4.1 is NOT an option, so group_concat is out.

CONCAT Length Limitation
I have encountered a problem while using the CONCAT command to update a column with a size over 1mb, the existing information is lost. I can't seem to find a suitable alternative to update a field in a row with several appends. the data length in total will be exceeding over 16mb at times.

Concat A Field In Up To 4 Rows?
A customer can have between 1 and 4 rows, is it possible to make a query that will merge field "A" of all rows and then discard all other rows leaving only 1 row left with the merged data in field "A".

GROUP CONCAT Issue
Iam using Mysql Version 5.0.

the query,

SELECT GROUP_CONCAT(field_name)FROM TABLE1;

This returns BLOG as result set in the editor in my Toad.

What is the issue, i have just 300 records in my table.

Why this happens, please help

Nesting A 'concat' Within A 'replace'
I have the_table:
col_1 , col_2
-------------------------
aaa , aaa_do aaa_dat

the query that I am using:"update the_table set col_2=replace(col_2,col_1,concat('hoorah_' , col_1) ) "

I want
col_1 , col_2
-------------------------
aaa , hoorah_aaa_do hoorah_aaa_dat

however the query does not successfully stick the 'hoorah_' in front of the aaa_dat; instead I get this:
col_1 , col_2
-------------------------
aaa , hoorah_aaa_do aaa_dat

Problem W/concat To Date
I am trying to run a report that displays data that falls between a date range. The dates are entered in mm/dd/yyyy format. I convert the date using ColdFusion code for MySQL to use:

cfset Start1c = DateFormat(#Start1#, "yyyy/mm/dd")
cfset End1c = DateFormat(#End1#, "yyyy/mm/dd")

The query that uses this variable will run as long as I,
1. use slashes in the date variable above
2. query for data that falls in the same year

Here is the part of my query that has a problem w/the formatting of this date:
date_format(date_sub(concat_ws('-',dataYear,dataMonth,'02'), interval 1 day), '%Y-%m-%d')
BETWEEN '#Start1c#' AND '#End1c#'
AND InputMethod = 1

dataYear and dataMonth are integer fields combined to create a date.

INSERT With Concat Auto_increment
I have a table that stores online orders. Each row in the table uses auto_increment to create a unique id for each order, in a field "id".

Each order (row in the table) also has a serial_number field that has a string representing the product and a unique number representing the order. I would like to append the id field value for the newly created order to the product string, to create the serial number.

Can this be done within a single SQL statement or do I need to insert the order, find out the id, then update the order and appending the id on the serial number string.

Is it possible to append the id of the newly inserted row to another field in the row in a insert statement?

I tried INSERT INTO orders SET serial_number = CONCAT('product text',id); but MySQL did not like the id column in the concat function.
Do I need to use LAST_INSERT_ID to find the id?

SELECT Where String Matches CONCAT Value?
I'm setting up a database where an order number is concat() of the company ID + order ID + timestamp year (2 digit). How would I find a string match to the order number without storing it explicitly in the database? Here's a simplified version of the 2 tables involved...

CREATE TABLE `companies` (
`id` int(10) unsigned NOT NULL auto_increment,
`prefix` varchar(3) NOT NULL,
`description` varchar(32) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE `orders` (
`id` int(6) unsigned zerofill NOT NULL auto_increment,
`company_id` int(10) unsigned NOT NULL,
`time_stamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

...and here's what I was trying to find an order number match:

SELECT orders.id
FROM orders
LEFT JOIN companies ON companies.id=orders.company_id
GROUP BY orders.id
HAVING (
CONCAT(companies.prefix, orders.id, '-', DATE_FORMAT(orders.time_stamp, '%y')) LIKE '%whatever%'
)

But I'm getting an error "#1054 - Unknown column 'companies.prefix' in 'having clause'". If I remember right, it's because I'm not selecting the fields from the having clause, and they're not in the group by statement. So, how would a fellow do what I'm trying to do? Should I just accept the redundancy and insert the full order number into the database?


Help With UPDATE Using CONCAT On Longtext Fields
I have two tables with longtext fields that I'd like to concatenate and update in one of the tables. Not sure if you can use concat on a longtext field. Here's what I tried:

UPDATE `node_revisions`, `weblink`
SET `node_revisions`.`body`=concat(`node_revisions`.`body`,"<br /><a href="",`weblink`.`weblink`,"">Visit this site</a>")
WHERE `node_revisions`.`nid` = `weblink`.`nid`;

This is the scenario. I have these 2 tables:

node_revisions table
-----------------------------
| id | nid | body (longtext) |
-----------------------------
| 1 | 23 | this is some text |
-----------------------------

weblink
-----------------------------
| id | nid | weblink (longtext) |
-----------------------------
| 5 | 23 | http://somesite.com |
-----------------------------

I'm trying to use UPDATE to concatenate the node_revision.body and weblink.weblink fields, where they share foreign key nid. So the resulting node_revisions would look like:

node_revisions table
-----------------------------
| id | nid | body (longtext) |
-----------------------------
| 1 | 23 | this is some text<br /><a href="http://somesite.com">Visit this site</a> |
-----------------------------

When I run the UPDATE statement above, I get the following feedback, but nothing has in fact changed:

Query OK, 813 rows affected (0.15 sec)
Rows matched: 813 Changed: 813 Warnings: 0

Concat Columns Based On Certain Criteria Using Only SQL?
I have a big table (15 million records). Each row has a parsed address (number, prefix, street, type, suffix) and I need to take these separate pieces and concatenate them. However, often times a few of those pieces will be blank, so I want to prevent any unnecessary spaces.

I'm using MySQL 4.1. I found some documentation for using if statements for MySQL 5.0, tho I dont know if any of it works in 4.1.

The basic psuedo code of what I want to do is this:

Create &amp; Store A Concat String
I have two tables:

keywords(itemID, WordID) and
words(WordID,Word)

I would like to create a single string of the words associated with a single ItemID by concatenating words and store them into a new table wordstring(itemID, wordstring).

Illegal Mix Of Collations When Using The Concat Function
SELECT concat('hello world ', cui)
FROM `umls_cuis`

I am using MySQL 4.1.3-beta. I get the following error when trying to execute the above SQL:

ERROR 1267: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (utf8_general_ci,IMPLICIT) for operation 'concat'

What can I do about it?

Usage Of CONCAT Operator When Creating A View ...
I am trying to create a view and my syntax is as follows :

CREATE OR REPLACE VIEW UDT_GRP_LDR_ACTIVE_V
( PRIKEY
, Leader
, Group_Name
, Group_Description
, Meeting_Frequency
, Meeting_Time
, Meeting_Day
, Sector
, Focus
, AUTO_IMAGE
, AUTO_SECURITY_AUTH )
AS
SELECT A.PRIKEY
, CONCAT (P.PER_FNAME, ' ', P.PER_LNAME) as Leader
, G.GRP_NAME
, G.GRP_DESC
, G.MTG_FREQUENCY
, G.MTG_TIME
, G.MTG_DAY
, G.SECTOR
, G.FOCUS
, P.AUTO_IMAGE
, A.AUTO_SECURITY_AUTH
FROM UDT_PER_GRP_ROLE A
LEFT OUTER JOIN UDT_PERSON P ON A.PER_ID = P.PRIKEY
LEFT OUTER JOIN UDT_CELL_GROUP_ACTIVE_V G ON A.GRP_ID = G.PRIKEY
WHERE A.STS_ID = 1
AND A.ROLE_ID = 4;

When I run this statement, I get the following error (in PHPMyAdmin) : "#1305 - FUNCTION hart7511_sope1.CONCAT does not exist".

At first I thought it was a permissions issue on my account and contacted the SysAdmin at my web hosting company. I'm still waiting for a response from them, but the strange thing is that when I just run the SELECT statement on its own (without the CREATE OR REPLACE VIEW part), it runs fine ... so despite the wording of the error message, the problem doesn't really seem to be with "CONCAT" ... or am I missing something ? BTW I have created other views without using CONCAT and had no issues.

Subqueries?
I'm using MySQL Control Center 0.9.2-beta. Will this take subqueries? I'm trying to extract data from tables in two different databases, and I'm not all familiar with JOINS. What is the syntax to do this in a subquery? In a JOIN?

Subqueries
I know (by internet) that mySQL is very fast. Problem is that my subqueries that are very fast in Access or SQL Server but they are very slowly in mySQL - since I have to restart my computer because mySQL freeze all the processes. (the resources where used at maximum - 2 Gb RAM, 2,5 Ghz processor)

This is the query :
SELECT NPL, PP FROM P_A INNER JOIN ACTIONS
ON P_A.NA =ACTIONS.ACT_N WHERE P_A.NA in
(SELECT NA FROM P_A WHERE NP ='ABC')

P_A has 5 columns and 12000 rows
Actions has 5 columns and 770 rows

Any suggestions ?

Subqueries With ALL
I got following statement:

SELECT * FROM ip WHERE id <> ALL (SELECT ipid FROM pcip);

Like I can see in the documentation, this should be correct, but SQL drops a SyntaxError near "ALL (SELECT ipid FROM pcip)"

What it dows should be ovious, select all IPs that IDs are not noticed in the PCIP table under IPID

The Tables are set up correct, means both tables exist and got values for the mentioned collums

My MySQL version is 4.0.21 if that is part of the problem...

Subqueries For V3.23
An upgrade is definately coming, as some some SQL practice, but I'm trying to figure out how to do a subquery and not entirely certain where to turn to.

From my limited understanding of SQL, what I want to do should look like:

SELECT
(SELECT count(SurveyData.Choice) WHERE SurveyData.Choice='0') as a,
(SELECT count(SurveyData.Choice) WHERE SurveyData.Choice='1') as b,
(SELECT count(SurveyData.Choice) WHERE SurveyData.Choice='2') as c
FROM SurveyData

The SurveyData table contains 3 fields: SID (Int), Name (Varchar 100), Choice (Int)

I'd like to use it as the basis for a reusable/scalable web survey app (perl CGI), but all I'm getting is a syntax error.

Subqueries
My host provider is running MySQL 4.0.24.

I have this query

SELECT `hbsclasses`.`classID`,
       `hbsclasses`.`className`,
        COUNT(`hbscompanies`.`classID`) AS Totals
FROM `hbscompanies`,
     `hbsclasses`
WHERE `hbscompanies`.`classID` = `hbsclasses`.`classID` GROUP BY `hbscompanies`.`classID`
ORDER BY Totals DESC LIMIT 0,25";

I need the results of this query to be sorted alphabetically on `hbsclasses`.`className`.

Use Of Subqueries With IN
I'm trying to do the following query:

select * from table1 where col1 in (select col1 from table2);

I keep getting a message to check my query after "in". But I've cut and pasted that query and it works. This is a very simple query so I don't understand why it doesn't work.

Subqueries
I'm more familiar with Microsoft flavors of SQL so I'm having some trouble with this.

Maybe some folks here can help.. I'm trying to query a few identical-structure tables.. so I'm tossing in some server side programming to generate it fast.. but I'll just give you guys the output and its giving me an error

Attempted Method 1:
select
      (select count(*) as p1_count from d1.Products as P, pdb.Manufacturers as HM where P.ManufacturerID = HM.AutoID) as p1,
      (select count(*) as p2_count from d2.Products as P, pdb.Manufacturers as HM where P.ManufacturerID = HM.AutoID) as p2,
      (select count(*) as p3_count from d3.Products as P, pdb.Manufacturers as HM where P.ManufacturerID = HM.AutoID) as p3

Subqueries
I have two tables, both linked by the primary key FieldIndex in the UserFieldsIndex table:

[UserFieldsIndex]
fieldIndex * fieldName
------------------------------
0 * Path
1 * ShortName

[UserFieldsTable]
fieldIndex * imageIndex * value
--------------------------------------------
0 * 500 * /toast
0 * 500 * /oldtoast
1 * 500 * lakeview
1 * 505 * worldview

The two tables are made so that a user can add any field (fields designated by fieldName) to any image (images designated by imageIndex), and then put in any value (or multiple values) for each field (designated by value).

the fieldIndex and imageIndex are both foreign keys in the UserFieldsTable

So the issue I am having is when i want to search for an image that has a Path of /toast AND a ShortName of lakeview.

I've tried joining and subquerying, but have had no success. I get stuck when i get to the WHERE specification (ie: very basically [but wrong] it would be:

WHERE (FieldIndex=0 && value=/toast) AND (FieldIndex=1 && value=lakeview)

Subqueries On 4.0.25 Without Subqueries
i have 2 tables. knowing subqueries cant be performed on this version how would i write the following statement?

i have 2 tables
table.a, table.b

I want to select all records from table.a that match table.a.id = table.b.id WHERE table.b.varchar = 'value'

once the table.b.varchar is found, get table.b.id and match it to any records in table.a.id that match it.

Can this be done in 1 statement. I'd hate to have to run a loop here. I've tried without success JOIN statements.

here is one of my attempts:
"SELECT table.a.* FROM table.a, table.b WHERE table.a.id = table.b.id AND table.b.varchar = '$value' GROUP BY table.a.sortkey ORDER BY table.a.is_primary DESC ";

this does return 1 row, and joins the 2 tables accordingly, however i need all rows in table.a that match the table.b.id where table.b.varchar = 'value'

Subqueries
I'm using mysql 4.17, and I'm trying to get an output of such a query:

UPDATE POST SET CLASS=1 WHERE ID IN (SELECT ID FROM POST ORDER BY RAND() LIMIT=300); but I obtain a respond message:

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

What should I do then? I really need to get this output.

SubQueries
I have been unsuccessfully trying to get a subquery to work.
here's the scenario:

My product is a list of student names and their #1 and #2 choice of majors.

tblStudent: ndxStudent, sName
tblMyMajors:ndxStudent, ndxMajor, priority (1 or 2)
tblMajors:ndxMajor, longDescr, status (Active/Inactive/Other)

My output should be:sName | major1 | major2

My logic is:
SELECT a.sName, b.longDescr, c.longDescr
FROM tblStudent a, tblMajors b, tblMajors c, tblMyMajors d
WHERE (a.ndxStudent=2)
AND (b.longDescr=(
SELECT e.longDescr
FROM tblMajors e, tblMyMajors f, tblStudent g
WHERE g.ndxStudent=2
AND f.priority=1
AND f.ndxMajor=e.ndxMajor))
AND (c.longDescr=(
SELECT h.longDescr
FROM tblMajors h, tblMyMajors i, tblStudent j
WHERE j.ndxStudent=2
AND i.priority=1
AND i.ndxMajor=h.ndxMajor))

This query produces a message that there's a syntax error at the first subquery.
My host is running MySQL 4.0.18-nt.

Subqueries With NOT IN And &lt;&gt; ALL
I am having troubles with the following on 4.0.22:
select *
from question as q
where q.id NOT IN (select distinct question from choice );

choice.question ---> question.id

Apparently there's a syntax error, at (select distinct ....)
<> ALL yields the same result.


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