wood burning stoves*
The moose likes JDBC and the fly likes MYSQL: a row with only one value the same in that field, extracted from table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MYSQL: a row with only one value the same in that field, extracted from table" Watch "MYSQL: a row with only one value the same in that field, extracted from table" New topic
Author

MYSQL: a row with only one value the same in that field, extracted from table

Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
MYSQL 5
How define in a SELECT applied for a particular field, a row with only one value the same in that field, extracted from table? this field required be PRIMARY KEY?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

I've probably misinterpreted your question, but I think you're looking for a WHERE clause.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
not where but yyy something like:

SELECT yyy(field1), field2, field3 from table where field=666; // look for yyy make field1(=email) only one in a given result set even have more entries...well?
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

Leonidas Savvides wrote:not where but yyy something like:

SELECT yyy(field1), field2, field3 from table where field=666; // look for yyy make field1(=email) only one in a given result set even have more entries...well?


sorry I have no idea what you mean, could you write some pseudo code explaining in long hand what you want.

Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
I mean keyword in front of a field make it unique, what the keyword(yyy in example)?
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

There is a DISTINCT keyword, which eliminates duplicates from the rows being fetched. This keyword is placed right after the SELECT. Then there is the GROUP BY clause, which is useful to obtain only one distinct value from a column or several columns, and some kind of aggregate values for the rest of columns. It comes right after the WHERE clause.

If you describe what exactly you need, we can try to point you in the right direction. Additionally, you might want to read some SQL tutorial.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
in a Mysql VIEW I used "join" to join two tables

...table1 join table2...

table2 has 2 entries(rows) and table1 has also 2 entries join by email(for a particular email), expected the result to return for this email(primary key) 2 rows(as many as table2 has for this email) return double 4 rows, in other words two rows have appeared twice,... the other data(customers) that had 1 in each table appeared normally as one row... well?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

That's how joins work. They take everything from the left table (table1), everything from the right table (table2), and match them. Depending on the join type it may omit results that appear on only one side. For example, an inner join removes results from either table that has no match in the other table, whereas a left outer join only removes results from the right table.

If a record in table1 has two matching records in table2, then the join will indeed have two rows. That's simply how joins work.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Could you post your whole query? The description of your problem looks like you didn't specify which field to join the table on. I don't know whether that would be syntax error in MySQL or not, though.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

Martin Vajsar wrote:Could you post your whole query? The description of your problem looks like you didn't specify which field to join the table on. I don't know whether that would be syntax error in MySQL or not, though.


I think it would just return every row in table 1 duplicated for every row in table 2. (is this called a cartisian product?)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MYSQL: a row with only one value the same in that field, extracted from table
 
Similar Threads
NX: Update owner in JTable
Urgent pls Help!!!
Update Table Nested Query (Using Function)
How to Determine Whether to Insert or Update
SQL query????