Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've probably misinterpreted your question, but I think you're looking for a WHERE clause.
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean keyword in front of a field make it unique, what the keyword(yyy in example)?
 
Martin Vajsar
Sheriff
Pie
Posts: 3751
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3751
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic