473,799 Members | 3,080 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1582
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.co m> wrote in message news:<co******* **@enews3.newsg uy.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
8349
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 possible to have conflicting data. I am looking to make a composite picture of a given security using the following rules: 1) The goal is to replace all NULL and Blank values with data
4
2284
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 companies on a form. 3 of the companies have common employees. I have a table that looks like this:
2
1309
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
8134
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 to have a fixed number of rows regardless of what data is in the bound table? Thanks, Aaron -- --- Aaron Smith
7
3391
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 either AND or OR but never mixed together. We can use Northwind database for my question, it is very similar to the structure of the problem on the database I am working on. IF(SELECT OBJECT_ID('REPORT')) IS NOT NULL DROP TABLE REPORT_SELECTION
68
6833
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
7183
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 failing rows exceeded the maximum specified" The number of rows shouldn't be a problem because in another DTS I copy a lot more rows. Also the width of the row shouldn't be a problem, I'm transfering only 3
3
1008
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 want to create different types of rows: InputRow, CheckRow, ...
7
1759
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 the text filed in the form but i dont want to go one by one and wirte disable="disabled" can i make calss or css (i realy dont know alot about it) and then just apllay it with one line ?
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10228
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.