Membership is FREE – with unlimited access to all features, tools, and discussions. Premium accounts get benefits like banner ads and newsletter exposure. ✅ Signature links are now free for all. 🚫 No AI-generated (LLM) posts allowed. Share your own thoughts and experience — accounts may be terminated for violations.

php query

Status
Not open for further replies.
Joined
Jan 19, 2007
Posts
2,207
Reaction score
47
I have a table where there are a bunch of fields. I'm trying to extract information for rows with a unique 'code' where subject='subject'. I also need the 'title' field entry from that row.

Here's my query:

$query="select distinct(code), title from tablename where subject='$subject' order by code asc";


Is this correct or can it cause problems that of the 2 variables I'm pulling, I'm specifying 1 as disctinct?
 
theoretically if you ask the puritans your not supposed to pull more than one column when specifying distinct. As your using orderby the distinct you may wanna alias it and set distinct code as distcode then order by distcode, otherwise some SQLs will order by all the code not just the distinct ones. (there maybe 1000 code lines but only 15 distinct ones).

I personally think if it works then its ll good :)
 
Status
Not open for further replies.

Rule #1: Be Respectful

Do not insult any other member. Be polite and do business. Thank you!

Premium Members

New Threads

Domain Forum Friends

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Siusaidh AcornBot:
    Siusaidh has left the room.
      Siusaidh AcornBot: Siusaidh has left the room.
      Top Bottom