Recherche id max en plus d'un autre champs

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Recherche id max en plus d'un autre champs

par mazou » 18 oct. 2005, 09:25

Essaye comme cela :
$query="
SELECT ibf_topics.title,  ibf_topics.tid, ibf_posts.post, ibf_posts.pid, ibf_posts.post_date 
FROM ibf_topics, ibf_posts 
WHERE ibf_topics.tid=ibf_posts.topic_id
GROUP BY ibf_posts.pid
HAVING ibf_posts.pid = max(ibf_posts.pid)";
Cette solution fonctionne !

Merci à tous

par mere-teresa » 14 oct. 2005, 10:51

J'ai cru comprendre que tu voulais tes champs et aussi le plus grand id...(MAX)...donc mets le comme un des champs que tu sélectionne et renomme le avec AS.

Code : Tout sélectionner

SELECT SELECT MAX(ibf_posts.pid) AS maximum, ibf_topics.title, ibf_topics.tid, ibf_posts.post, ibf_posts.pid, ibf_posts.post_date FROM ibf_topics, ibf_posts WHERE ibf_topics.tid=ibf_posts.topic_id ORDER BY ibf_topics.tid desc
http://www.nexen.net/docs/mysql/annotee ... p?lien=max

par Augure » 14 oct. 2005, 10:41

Essaye comme cela :
$query="
SELECT ibf_topics.title,  ibf_topics.tid, ibf_posts.post, ibf_posts.pid, ibf_posts.post_date 
FROM ibf_topics, ibf_posts 
WHERE ibf_topics.tid=ibf_posts.topic_id
GROUP BY ibf_posts.pid
HAVING ibf_posts.pid = max(ibf_posts.pid)";

par mazou » 12 oct. 2005, 09:44

SAlut, en 2 requetes ?!
une pour trouver le max et une autre (la meme que tu as) + clause where sur ibf_posts.pid=Max(trouvé) :-k
Oui en 2 requête je sais le faire (c d'ailleurs ce que j'ai fait).
Mais j'aurai aimé le faire en une

par Truc » 11 oct. 2005, 18:35

SAlut, en 2 requetes ?!
une pour trouver le max et une autre (la meme que tu as) + clause where sur ibf_posts.pid=Max(trouvé) :-k

Recherche id max en plus d'un autre champs

par mazou » 11 oct. 2005, 15:10

Bonjour,

Je bloque sur une recherche dans des tables mysql.

Ma recherche n'avait pour l'instant rien de compliqué, il s'agissait juste de croiser des tables.

Seulement maintenant je veux trouver en plus l'enregistrement max d'un champ.

Voici ma requête :
$query="SELECT ibf_topics.title,  ibf_topics.tid, ibf_posts.post, ibf_posts.pid, ibf_posts.post_date FROM ibf_topics, ibf_posts where ibf_topics.tid=ibf_posts.topic_id  order by  ibf_topics.tid desc";
Je voudrais qu'en plus que de cette recherche elle ne me donne que l'enregistrement avec le chiffre le plus important dans le champs pid (ibf_posts.pid).

QQ'un as-t-il une solution ???

Merci d'avance