Jump to content


Photo

mysql / php help


  • Please log in to reply
7 replies to this topic

#1 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 28 August 2006 - 04:51 AM

I was wondering, is it possible to select records from two different tables in one query?

If so can somebody show me a theoretical example? I would like to use this for a php script.

Thanks in advance fo any help.

#2 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 28 August 2006 - 05:08 AM

SELECT username FROM users,monkies WHERE test = 1

I think this would be the correct syntax for doing this... 

#3 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 28 August 2006 - 05:13 AM

Thanks, that was really helpful!

#4 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 28 August 2006 - 05:16 AM

Now the question is, does it work...  lol..  I haven't actually tested that right this second but i did it once and i think thats the way i did it...

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 28 August 2006 - 05:41 AM

yes it is possible. doing something as simple as this will work:

select * from table1,table2

was that the end-all-be-all of your question, or were you trying to do something specific?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 28 August 2006 - 10:22 PM

Please use proper JOIN syntax... you'll thank me later.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 28 August 2006 - 11:34 PM

yes it is possible. doing something as simple as this will work:

select * from table1,table2


@CV,

Yes, it will work but inless you specify how the tables should be joined you get every row in table1 joined with every row in table2 (cartesian join) so if you have 100 rows in each table you get 10,000 rows returned
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 29 August 2006 - 04:39 AM

yeah i know. my example was more along the lines of uh..cheekiness? sarcasm? it was more of an effort to get him to be more specific :)
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users