Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> zapytanie z 2 tabel - skomplikowane
pbern
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 3.07.2003

Ostrzeżenie: (0%)
-----


Mam 2 tabele.. jedna to tabela z towarami, druga z diagnostykami (przy czym w tej drugiej moze byc X rekordow dotyczacych jednego towaru)

moje pytanie to jak napisac zapytanie ktore by wyciagalo dane dotyczace towaru + ostatnia z diagnostyk dotyczaca tego towaru.

Struktura bazy:
[sql:1:bafb259a7c]
CREATE TABLE goods (
id int(11) NOT NULL auto_increment,
id_client int(11) NOT NULL default '0',
goods_name varchar(128) NOT NULL default '',
place varchar(16) default NULL,
sn varchar(32) NOT NULL default '',
nr_rachunku varchar(32) NOT NULL default '',
destription blob NOT NULL,
data_in date NOT NULL default '0000-00-00',
worker int(11) NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)
) TYPE=MyISAM PACK_KEYS=0 CHECKSUM=1 AUTO_INCREMENT=31 ;

CREATE TABLE diagnostyki (
id int(11) NOT NULL auto_increment,
id_goods int(11) NOT NULL default '0',
diagnoza text NOT NULL,
worker int(11) NOT NULL default '0',
data timestamp(14) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY id (id)
) TYPE=MyISAM AUTO_INCREMENT=94 ;

[/sql:1:bafb259a7c]
Ja wykombinowalem takie cos

[sql:1:bafb259a7c]
select goods.id,goods.goods_name,diagnostyki.diagnoza from goods,diagnostyki where diagnostyki.id_goods=goods.id ORDER by id;
[/sql:1:bafb259a7c]

jednak wykorzystuje on wszytkie diagnostyki dla danego towaru.. a mnie interesuje tylko ostatnia.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.09.2025 - 17:33