Kevin
Kevin

Reputation: 4848

How can I get a subset of rows from Oracle database?

I'm not sure if that's the right question, but what I'm trying to do is get only certain rows from an Oracle database table. The data might look like this:

Mark Jameson 1218 Hwy 82 W
Mark Jameson 1218 Hwy 82 W
Vann Jameson 1222 Hwy 82 W
Vann Jameson 1222 Hwy 82 W
Roy  Myers   118 Grey Street
Roy  Myers   118 Grey Street

I'd like to have my SELECT only grab one unique record from each 'name grouping', if that makes sense, so that I get the following result:

Mark Jameson 1218 Hwy 82 W
Vann Jameson 1222 Hwy 82 W
Roy  Myers   118 Grey Street

I was looking at using the DISTINCT keyword, but I'm not sure that's what I need. A push in the right direction would be greatly appreciated.

Thank you!

Upvotes: 1

Views: 238

Answers (2)

Diego
Diego

Reputation: 36146

or you can use a group by without any aggregation function

SELECT name, last_name, column2, column3, column4, column5
FROM your_table
GROUP BY name, last_name, column2, column3, column4, column5

Upvotes: 1

MatBailie
MatBailie

Reputation: 86706

Depending on what you need, either of these should work (using your real field names)

SELECT
  a, b, c, d
FROM
  yourTable
GROUP BY
  a, b, c, d

SELECT
  DISTINCT
  a, b, c, d
FROM
  yourTable

Upvotes: 2

Related Questions