I'm told "select distinct on" or even "select distinct" is inefficient
because it selects then discards rows.
However, I'm stumped to find an alternative to this query :
select distinct on (user_id) * from bids where auction_id = 3 order by
user_id,created _at DESC;
I'm trying to retreive only the last bid for each user for a given auction.
I'd appreciate any suggestions.
The schema:
CREATE TABLE auctions ( id serial NOT NULL, user_id int4, title
varchar(255), body varchar(255), CONSTRAINT auctions_pkey PRIMARY KEY (id) )
WITHOUT OIDS;
CREATE TABLE bids ( id serial NOT NULL, auction_id int4, user_id int4,
amount float8, created_at timestamp, CONSTRAINT bids_pkey PRIMARY KEY (id) )
WITHOUT OIDS;
CREATE TABLE users ( id serial NOT NULL, username varchar(255), CONSTRAINT
users_pkey PRIMARY KEY (id) ) WITHOUT OIDS; 0 4163 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ben |
last post by:
This is a PHP / MySQL kind of question. I am making a script which
simply pulls information from a database and displays it on screen. BUT
there will be entries where fields could be the same, and I want to
eliminate the duplicate entries when it displays it on screen.
I would use,
SELECT DISTINCT 'address1' FROM orders
....which does work, but only gives me one field. I also need to get a
|
by: Martin Feuersteiner |
last post by:
Dear Group
I'm having trouble with the clause below. I would like to select only
records with a distinct TransactionDate but somehow it still lists
duplicates. I need to select the TransactionDate once as smalldatetime and
once as varchar as I'm populating a drop-down with Text/Value pairs. So I
can't just use 'SELECT DISTINCT TransactionDate FROM...'
I'm grateful for any hints.
|
by: Leny |
last post by:
Hi,
Since Access doesn't support COUTN DISTINCT, I'm facing a new
problem I didn't take into account: how to get the count of PK's in a
complex query. I create queries on the fly -this means I can't use a
stored macro or even a query view-.
A simple example: Let's say you have a simple database with three
tables: People, Laguages and a table with the relationship between
them. How do you retrieve the count of persons who don't speak...
|
by: mathilda |
last post by:
My boss has been adamant that SELECT DISTINCT is a faster query than
SELECT all other factors being equal. I disagree. We are linking an
Access front end to a SQL Server back end and normally are only
returning one record. She states that with disctinct the query stops
as soon as it finds a matching record. Both of us are relative novices
in database theory (obviously).
Can someone help settle this?
|
by: nfrodsham |
last post by:
In Microsoft's help literature, it states:
"You can filter out non-unique rows by using the DISTINCT option of an
aggregate function"
I am trying to do this in Access 2003 with the COUNT aggregate
function, but there is no reference, at least that I can find anywhere,
of how to do this. I have multiple lines fields for which I would like
to do a "count distinct", but for simplicity, I am showing an example
of only one field. Here is...
| |
by: orekinbck |
last post by:
Hi There
Our test database has duplicate data:
COMPANYID COMPANYNAME
1 Grupple Group
2 Grupple Group
5 Grupple Group
3 Yada Inc
4 Yada Inc
|
by: ian |
last post by:
Does anyone know what the best alternative to using frames? I've looked at
Object but this doesn't seem to work in IE6...
TIA
Ian
|
by: Techhead |
last post by:
I need to run a SELECT DISTINCT query across
multiple fields, but I need to add another field that is NON-DISTINCT
to my record set.
Here is my query:
SELECT DISTINCT lastname, firstname, middleinitial, address1,
address2, city, state, zip, age, gender
FROM gpresults
|
by: maddamon |
last post by:
My problem looks like that:
SELECT * FROM `table` where `attribute` = '24'
INTERSECT
SELECT * FROM `table` where `attribute` = '16';
and my 'table' structure is : product_attributes(products_attributes_id, products_id, options_id, options_values_id, options_values_price, price_prefix)
I have this query and i`d like to have all products from the same table but with 2 different values and only with this values of 'attribute'.
|
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...
|
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,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |