[SQL]Drobny problem z 'ORDER BY' na 4 tabelach (INNER JOIN)

Wszystko o językach skryptowych takich jak PHP i Perl, serwerach WWW, CGI, bazach danych i języku SQL.
zdenoslaw
Posty: 7
Rejestracja: 14 sty 2016, 12:05:10
Płeć: Niewybrana
User Agent: Firefox Windows 1440x900

[SQL]Drobny problem z 'ORDER BY' na 4 tabelach (INNER JOIN)

Post autor: zdenoslaw »

Mam takie oto zapytanie:

Kod: Zaznacz cały

"SELECT po.thread_id, po.post_message, po.post_author, MIN(po.post_datestamp) AS post_datestamps, th.thread_subject, th.thread_views, th.thread_postcount, th.thread_lastpost, fo.forum_name, us.user_name, us.user_status, MIN(po.post_id) AS posts_id FROM ".DB_POSTS." AS po INNER JOIN ".DB_THREADS." AS th ON po.thread_id=th.thread_id INNER JOIN ".DB_FORUMS." AS fo ON po.forum_id=fo.forum_id INNER JOIN ".DB_USERS." AS us ON po.post_author=us.user_id GROUP BY th.thread_id ORDER BY po.thread_id DESC LIMIT 30;"
Kod działa i na pierwszy rzut oka wydaje się zwracać prawidłowe wartości czyli pola w wierszach powiązanych z pierwszym postem w danym temacie. Niestety jest jeden wyjątek:
Temat 'Music on 2paq' (thread_id=15) zwraca post nr 6 (post_id=44) zamiast nr 1 (post_id=22).

Więc pytam ewentualnych ekspertów z tego forum czy istnieje jakaś niezawodna metoda pobrania wartości których potrzebuję i co jest problemem z obecną metodą?

Efekt powyższego zapytania: http://2paq.cba.pl/viewpage.php?page_id=4&Stats=Threads
Zapytanie jest wykonywane przez funkcję dbquery() zgodnie z dokumentacją PHP-Fusion: https://www.php-fusion.co.uk/infusions/ ... hp?page=80
Dostępne pola w bazie danych:

Kod: Zaznacz cały

DB_THREADS:
Key=forum_id
Key=thread_id
Key=thread_subject
Key=thread_author
Key=thread_views
Key=thread_lastpost
Key=thread_lastpostid
Key=thread_lastuser
Key=thread_postcount
Key=thread_poll
Key=thread_sticky
Key=thread_locked
Key=thread_hidden
DB_POSTS:
Key=forum_id
Key=thread_id
Key=post_id
Key=post_message
Key=post_showsig
Key=post_smileys
Key=post_author
Key=post_datestamp
Key=post_ip
Key=post_ip_type
Key=post_edituser
Key=post_edittime
Key=post_editreason
Key=post_hidden
Key=post_locked
DB_FORUMS:
Key=forum_id
Key=forum_cat
Key=forum_name
Key=forum_order
Key=forum_description
Key=forum_moderators
Key=forum_access
Key=forum_post
Key=forum_reply
Key=forum_poll
Key=forum_vote
Key=forum_attach
Key=forum_attach_download
Key=forum_lastpost
Key=forum_postcount
Key=forum_threadcount
Key=forum_lastuser
Key=forum_merge
DB_USERS:
Key=user_id
Key=user_name
Key=user_algo
Key=user_salt
Key=user_password
Key=user_admin_algo
Key=user_admin_salt
Key=user_admin_password
Key=user_email
Key=user_hide_email
Key=user_offset
Key=user_avatar
Key=user_posts
Key=user_threads
Key=user_joined
Key=user_lastvisit
Key=user_ip
Key=user_ip_type
Key=user_rights
Key=user_groups
Key=user_level
Key=user_status
Key=user_actiontime
Key=user_theme
Key=user_location
Key=user_birthdate
Key=user_skype
Key=user_aim
Key=user_icq
Key=user_msn
Key=user_yahoo
Key=user_web
Key=user_sig 
ODPOWIEDZ