[Webinar] Learn how to a build a cloud-first strategyRegister Now


Select in Select using Uniqueindentifier as the key

Posted on 2006-04-20
Medium Priority
Last Modified: 2008-01-09
I have 2 tables, adxprofile is the main table, adxProfileValues is the child table.
They are joined by a field called adxProfileGuid.

I want to query send the query the userkey which is the username.
The query then in turn needs to return all the child rows with the matching uniqueindentifier

I have the following statement

select adxProfileGuid
from adxprofile
where userkey = 'john'
and adxProfileGuid =
(select PropertyName
from adxProfileValues)

When I use = I get this error
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

When I use IN instead of = I get this error
Syntax error converting from a character string to uniqueidentifier.
Question by:gspronych
LVL 15

Expert Comment

ID: 16502903
Use IN and then use the CONVERT function on PropertyName

Author Comment

ID: 16502960
I get this error
Syntax error converting from a character string to uniqueidentifier.

It seems to me that using the IN statement coverts the GUID into a string.
I have tried adding convert statements to the adxProfileGuid with the same results.
LVL 34

Expert Comment

by:Brian Crowe
ID: 16503271
Could you please translate the sentence below...

"I want to query send the query the userkey which is the username."

Author Comment

ID: 16503315
Sorry for the bad gramar

I want the first query to use the GUID field in adxProfileGuid from adxprofile
select adxProfileGuid
from adxprofile
where userkey = 'john'

And return all the matching rows from adxProfileValues.
adxProfileValues has the same adxProfileGuid field with the same GUID.

Thanks for your assistance
LVL 75

Accepted Solution

Anthony Perkins earned 2000 total points
ID: 16503887
This will return all the rows in adxProfileValues that match adxprofile and where userkey = "john'':

select v.*
from adxprofile p
         Inner Join adxProfileValues v On p.adxProfileGuid = v.adxProfileGuid
where p.userkey = 'john'

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question