Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SQL]Zapytanie SQL JOIN
sannin
post
Post #1





Grupa: Zarejestrowani
Postów: 308
Pomógł: 13
Dołączył: 31.10.2008

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


Witam,

chcę wybrać z bazy użytkowników którzy przez ostatnie 30 dni nie dodali żadnego zdjęcia. Zbudowałem takie zapytanie

Kod
SELECT user_name FROM cpg14x_users JOIN cpg14x_pictures ON (ctime < (NOW() - 2592000))


Ale zwraca mi loginy wszystkich userów czy coś takiego
Cytat
(NOW() - 2592000))
jest błędem?

Ten post edytował sannin 6.05.2009, 20:43:29
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kefirek
post
Post #2





Grupa: Zarejestrowani
Postów: 781
Pomógł: 256
Dołączył: 29.06.2008

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


Złączasz tabele za pomocą LEFT JOIN najlepiej pokaż strukture tabeli
Go to the top of the page
+Quote Post
sannin
post
Post #3





Grupa: Zarejestrowani
Postów: 308
Pomógł: 13
Dołączył: 31.10.2008

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


Zamiast
Kod
NOW()
powinno być
Kod
SELECT unix_timestamp(now())


Cytat(kefirek @ 6.05.2009, 22:14:14 ) *
Złączasz tabele za pomocą LEFT JOIN najlepiej pokaż strukture tabeli


Tak właśnie robię, ale wywala mi wszystkich użytkowników

Kod
SELECT cpg14x_users.user_name FROM cpg14x_users LEFT JOIN (cpg14x_pictures) ON (cpg14x_users.user_id = cpg14x_pictures.owner_id AND cpg14x_pictures.ctime < 1239046922) GROUP by cpg14x_users.user_name


Wygląda na to, że ignoruje to
Kod
cpg14x_users.user_id = cpg14x_pictures.owner_id AND cpg14x_pictures.ctime < 1239046922
bo nawet jak wpiszę tam sprzeczne dane to wyświetla wszystkich. Struktura tabeli
Kod
--
-- Struktura tabeli dla  `cpg14x_users`
--

CREATE TABLE `cpg14x_users` (
   `user_id` int(11) NOT NULL auto_increment,
   `user_group` int(11) NOT NULL default '2',
   `user_active` enum('YES','NO') collate utf8_unicode_ci NOT NULL default 'NO',
   `user_name` varchar(25) collate utf8_unicode_ci NOT NULL,
   `user_password` varchar(40) collate utf8_unicode_ci NOT NULL,
   `user_lastvisit` datetime NOT NULL default '0000-00-00 00:00:00',
   `user_regdate` datetime NOT NULL default '0000-00-00 00:00:00',
   `user_group_list` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user_email` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user_profile1` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user_profile2` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user_profile3` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user_profile4` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user_profile5` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user_profile6` text collate utf8_unicode_ci NOT NULL,
   `user_profile7` text collate utf8_unicode_ci NOT NULL,
   `user_actkey` varchar(32) collate utf8_unicode_ci NOT NULL,
   `auto_subscribe_post` tinyint(4) NOT NULL default '1',
   `auto_subscribe_comment` tinyint(4) NOT NULL default '1',
   `avatar_url` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user_pmsmail` tinyint(4) NOT NULL default '1',
   `enable_admin_email` tinyint(4) NOT NULL default '1',
   `picid_url` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user_sub` varchar(25) collate utf8_unicode_ci NOT NULL,
   PRIMARY KEY  (`user_id`),
   UNIQUE KEY `user_name` (`user_name`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Used to store users, not used when bridged' AUTO_INCREMENT=929;


Kod
CREATE TABLE `cpg14x_pictures` (
   `pid` int(11) NOT NULL auto_increment,
   `aid` int(11) NOT NULL default '0',
   `filepath` varchar(255) collate utf8_unicode_ci NOT NULL,
   `filename` varchar(255) collate utf8_unicode_ci NOT NULL,
   `filesize` int(11) NOT NULL default '0',
   `total_filesize` int(11) NOT NULL default '0',
   `pwidth` smallint(6) NOT NULL default '0',
   `pheight` smallint(6) NOT NULL default '0',
   `hits` int(10) NOT NULL default '0',
   `mtime` datetime NOT NULL default '0000-00-00 00:00:00',
   `ctime` int(11) NOT NULL default '0',
   `owner_id` int(11) NOT NULL default '0',
   `owner_name` varchar(40) collate utf8_unicode_ci NOT NULL,
   `pic_rating` int(11) NOT NULL default '0',
   `votes` int(11) NOT NULL default '0',
   `title` varchar(255) collate utf8_unicode_ci NOT NULL,
   `caption` text collate utf8_unicode_ci NOT NULL,
   `keywords` varchar(255) collate utf8_unicode_ci NOT NULL,
   `approved` enum('YES','NO') collate utf8_unicode_ci NOT NULL default 'NO',
   `galleryicon` int(11) NOT NULL default '0',
   `user1` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user2` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user3` varchar(255) collate utf8_unicode_ci NOT NULL,
   `user4` varchar(255) collate utf8_unicode_ci NOT NULL,
   `url_prefix` tinyint(4) NOT NULL default '0',
   `pic_raw_ip` tinytext collate utf8_unicode_ci,
   `pic_hdr_ip` tinytext collate utf8_unicode_ci,
   `lasthit_ip` tinytext collate utf8_unicode_ci,
   `position` int(11) NOT NULL default '0',
   PRIMARY KEY  (`pid`),
   KEY `pic_hits` (`hits`),
   KEY `pic_rate` (`pic_rating`),
   KEY `aid_approved` (`aid`,`approved`),
   KEY `pic_aid` (`aid`),
   KEY `owner_id` (`owner_id`),
   FULLTEXT KEY `search` (`title`,`caption`,`keywords`,`filename`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Used to store data about individual pics' AUTO_INCREMENT=2079;


Ten post edytował sannin 6.05.2009, 22:00:02
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 16.10.2025 - 06:38