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




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?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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?

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 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?


Select Subquery
I am having difficulty in the following subquery. I keep getting the syntax error at 'SELECT count(*)'.

SELECT ID, organization, (SELECT count(*) FROM Invoices WHERE paid = 'N') AS paid
FROM clients

What I am trying to do is to get a list of clients and also count any unpaid invoices.

Does anyone know what I am doing wrong.

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

Question W/ SELECT Query - Need A Subquery?

I have 2 tables:
*user - each row is a user
*interest - each row is a relation between a user and an interest

I am trying to construct a query to determine all other users that share overlapping interests; and also report the total number of interests these users have. I am having diffculty extracting the part in bold.

The following query will extract everything, but the part in bold:

Quote:

SELECT DISTINCTROW *, count(u.userid) AS matches
FROM interest f1, user u
WHERE f1.userid=u.userid AND f1.interestID IN ($qstr)
GROUP BY f1.userid
ORDER BY matches DESC
LIMIT 0,10

note that $qstr contains a list of all interest IDs that the reported users must share.

I have now built the following query, which doesn't work:

Quote:

SELECT DISTINCTROW *, count(u.userid) AS matches, count(f2.interestID) AS denom
FROM interest f1, user u, interest f2
WHERE f1.userid=u.userid AND f1.interestID IN ($qstr) AND f1.userid=f2.userid
GROUP BY f1.userid, f2.userid
ORDER BY matches DESC, denom DESC
LIMIT 0,1

Can You Select And Concat Multiple Items Separated By "," ?
The select I have finds multiple values for a field. I want to take that field and create ONE field separated by commas.

Is that possible? I could do it in PHP but it will be easier programmatically if I can do it here.

For example:

HTML
Select field1 where x=2;
val1
val2
val3
val4
I want it to be like:

HTML
Select field1 where x=2;
val1, val2, val3, val4
where "val1, val2, val3, val4" is ONE field I can then use.

I am actually using this as a subquery so it's not as easy as php's explode/implode.

Find Users With Similar Tastes / Select Count Of Subquery & Maintain Column Assignmts
The ultimate goal of the query:
List users by similarity in taste to user 1 based on the similarity of their favorite sites.

Setup
table users:
id, etc.

table sites:
id, etc.

table favorites:
user_id, site_id

Users add sites to their favorites list, a row is inserted into the favorites table associating users and sites.

Criteria for "similarity of taste":
%similarity = (number of intersecting favorites) / (number of unique favorites between them)

My attempt:


SELECT COUNT(*) / (SELECT COUNT(*) FROM
(SELECT DISTINCT id FROM favorites WHERE favorites.user_id = u2.id OR favorites.user_id = 1) as unique_favs)
as p_match,
u2.*
FROM favorites as f1
JOIN favorites as f2 ON f2.site_id = f1.site_id AND f2.user_id != 1
JOIN users as u2 ON u2.id = f2.user_id
WHERE f1.user_id = 1
GROUP BY u2.id
ORDER BY p_match DESC
LIMIT 30
The error:
Unknown column 'u2.id' in 'where clause'

Apparently column associations are "forgotten" when doing a derived table subquery.

Any ways I can fix this? Or any preferred methods of achieving the same result?


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)

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.....

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

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.


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?

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.

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)

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

Using NOT IN In A Subquery
I am using MySQL version 4.0.27-standard

everytime i use "not in" in the subquery:

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 .....

Subquery
Hi, wanted to use a subquery, as in:

SELECT * FROM pending WHERE username = (SELECT username FROM ratings);

But have learned subqueries are only available in MySQL 4.21 or later...

So...

I've tried to use the following query:


Code:

SELECT ratings.username,pending.username FROM
ratings,pending WHERE ratings.username="jjfjunk" OR
pending.username="jjfjunk";



But this returns an empty set, even though I know that the username exists in the ratings table.

Subquery
Can help to find any sytanx error from the following command?

select IMG_ID
FROM image
WHERE WORM_Name IN (SELECT WORM_Name FROM worm WHERE WORM_Age='adult')

I don't know where is wrong of above, but always got the sytanx error messange after I type in the above commands.


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