W
WebRaster
Hi to everyone, I need an helping hand on this question:
I'm bulding an home page of a cars seller, I need to display in this page
nine photos and descriptions taken by the database, 5 of this are fixed BUT
the other 4 elements had to be choosen in database according these select
criteria: the cheapest, the last two cars inserted in database, and the most
clicked in site. In addiction I have to avoid the accidental repetition of
elements on page, for example the ceapest car could be the last inserted in
database so could be displayed twice.
With the same query I have to extract from database these informations:
1) the cheapest one
2) the last two cars inserted in database
3) most clicked
The database structure in this:
Id (key)
product_name (text)
description (Memo)
price (number)
number_of_click (number)
insertion_data (Date)
My question is: how can I create a query that can work to solve this
problem?
--------------------------------
table statement
CREATE TABLE TABELLA1
(id CHAR(5) PRIMARY KEY,
product_name CHAR(20) NOT NULL,
description CHAR(255) NOT NULL,
productor CHAR(50) NOT NULL,
price DECIMAL(7, 2) NOT NULL,
number_of_click INTEGER,
insertion_data DATE NOT NULL);
-----------------------------------------------------
insert statement
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('1', 'Fiat 500 SL', 'etc. etc.', 'FIAT', 3000, '1-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('2', 'Fiat 1500 SQ', 'etc. etc.', 'FIAT', 8200, '10-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('3', 'Lancia Matra', 'etc. etc.', 'Lancia', 6800, '1-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('4', 'Maserati SL', 'etc. etc.', 'Maserati', 13000, '2-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('5', 'Volvo 980', 'etc. etc.', 'Volvo', 9600, '8-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('6', 'Fiat 500 SL', 'etc. etc.', 'FIAT', 9150, '11-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('7', 'Fiat 850 SP', 'etc. etc.', 'FIAT', 7100, '1-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('8', 'Fiat 1500', 'etc. etc.', 'FIAT', 9200, '1-AGO-2003');
--------------------------------------------
I start to try this query:
SELECT top 1 * FROM Tabella1 WHERE id NOT IN (SELECT top 2 * FROM Tabella1
ORDER by id DESC) ORDER BY number_of_click DESC;
and I receive this error:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Microsoft Access Driver] You have written a subquery that
can return more than one field without using the EXISTS reserved word in the
main query's FROM clause. Revise the SELECT statement of the subquery to
request only one field
What can I have to do
I'm bulding an home page of a cars seller, I need to display in this page
nine photos and descriptions taken by the database, 5 of this are fixed BUT
the other 4 elements had to be choosen in database according these select
criteria: the cheapest, the last two cars inserted in database, and the most
clicked in site. In addiction I have to avoid the accidental repetition of
elements on page, for example the ceapest car could be the last inserted in
database so could be displayed twice.
With the same query I have to extract from database these informations:
1) the cheapest one
2) the last two cars inserted in database
3) most clicked
The database structure in this:
Id (key)
product_name (text)
description (Memo)
price (number)
number_of_click (number)
insertion_data (Date)
My question is: how can I create a query that can work to solve this
problem?
--------------------------------
table statement
CREATE TABLE TABELLA1
(id CHAR(5) PRIMARY KEY,
product_name CHAR(20) NOT NULL,
description CHAR(255) NOT NULL,
productor CHAR(50) NOT NULL,
price DECIMAL(7, 2) NOT NULL,
number_of_click INTEGER,
insertion_data DATE NOT NULL);
-----------------------------------------------------
insert statement
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('1', 'Fiat 500 SL', 'etc. etc.', 'FIAT', 3000, '1-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('2', 'Fiat 1500 SQ', 'etc. etc.', 'FIAT', 8200, '10-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('3', 'Lancia Matra', 'etc. etc.', 'Lancia', 6800, '1-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('4', 'Maserati SL', 'etc. etc.', 'Maserati', 13000, '2-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('5', 'Volvo 980', 'etc. etc.', 'Volvo', 9600, '8-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('6', 'Fiat 500 SL', 'etc. etc.', 'FIAT', 9150, '11-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('7', 'Fiat 850 SP', 'etc. etc.', 'FIAT', 7100, '1-AGO-2003');
INSERT INTO TABELLA1
(id, product_name, description, productor, price, insertion_data)
VALUES
('8', 'Fiat 1500', 'etc. etc.', 'FIAT', 9200, '1-AGO-2003');
--------------------------------------------
I start to try this query:
SELECT top 1 * FROM Tabella1 WHERE id NOT IN (SELECT top 2 * FROM Tabella1
ORDER by id DESC) ORDER BY number_of_click DESC;
and I receive this error:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Microsoft Access Driver] You have written a subquery that
can return more than one field without using the EXISTS reserved word in the
main query's FROM clause. Revise the SELECT statement of the subquery to
request only one field
What can I have to do