473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

get rows that have a filed in common with another row

Hello,
I'm new to mysql (and databases, fo that matter) and have problems
finding a solution. The situation is as follows:
I have one table with filtered information about users, the columns
are, say, id, field and value. As you can see, any id can have more
rows assiciated with him, each containing one crucial piece of
information. Now I want to search the values for something and return
all rows with the same id -- in effect this means that I cannot use
"select * from t where value like ... ", which does, of course, return
all rows that match the expression rather than all rows with the same
id that happened to also contain a value with the expression.

If I'm not clear enough, here's an example:

id field value
--|-----|-------
a x string1
a y string2
b x string3
a z string4

"select * from t where value like string2" returns the second row, but
I want to return all rows with the same id as in row number two.

I've tried this subquery, to no avail: select * from t where id =
(select id from t where value like '%string2%' limit 1)

Thanks,

andrej
Jul 20 '05 #1
2 1569
andrej h wrote:
"select * from t where value like string2" returns the second row, but
I want to return all rows with the same id as in row number two.

I've tried this subquery, to no avail: select * from t where id =
(select id from t where value like '%string2%' limit 1)


Subqueries work in MySQL 4.1, but not in earlier versions.

It seems like if you can use subqueries, this might do what you want:

SELECT * FROM t WHERE id IN (SELECT DISTINCT id FROM t WHERE VALUE LIKE
'%string2%')

If you can't use subqueries I think this works:

SELECT DISTINCT t1.* FROM t AS t1 INNER JOIN t AS t2 ON t1.id = t2.id
WHERE t2.value LIKE '%string2%'

Regards,
Bill K.
Jul 20 '05 #2
Bill Karwin <bi**@karwin.com> wrote in message news:<co*********@enews3.newsguy.com>...
If you can't use subqueries I think this works:

SELECT DISTINCT t1.* FROM t AS t1 INNER JOIN t AS t2 ON t1.id = t2.id
WHERE t2.value LIKE '%string2%'


Turns out I can't use subqueries after all but this really wokrs!
However it'll take a while untill I understand all of it, but that's
my homework.

Thanks a lot,

andrej
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jason | last post by:
I need to populate a table from several sources of raw data. For a given security (stock) it is possible to only receive PARTS of information from each of the different sources. It is also...
4
by: Laura | last post by:
Here's the situation: I'm trying to use an update query to copy data from one row to another. Here is the situation: I have 5 companies that are linked to each other. I need to show all 5...
2
by: Shiye | last post by:
Help...! Hi all, Does any of you know how can determine the default value of a filed to be taken from another feild (already filled) in the same row of the table??? Thanks, Shai
10
by: Aaron Smith | last post by:
If I have a datagrid and the bound data file only have 4 rows in it, the grid will show the 4 rows. However, there is blank space below that until it reaches the bottom of the grid. Is there a way...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
1
by: David Greenberg | last post by:
Hello I am running a DTS (Sql 2000) and transfering data from an SqlServer database to an Ingres database. I am transfering 153k rows. Execution fails with the error message: "The number of...
3
by: shapper | last post by:
Hello, I created a custom control, Parent, with the following property: Property Rows As Generic.List(Of Row) Row is another custom control that creates some code. The problem is that I...
7
by: Amzul | last post by:
hello all. can someone tell if its possible to put <strong> inside the value? whats the right syntax? and another Q is it possible to applay new style to a form i mean i want to disable all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.