Jump to content

JOIN


Masna

Recommended Posts

I need some help with JOIN. I've never used it before, and right now is the time. I have one table, where I store "contacts" for users. Then, I grab all these contact ids for the logged in user, and use IN() to get the information from a users table on these contacts. How can I grab all the information I need via one query, via JOIN? Thanks.
Link to comment
Share on other sites

Nevermind, JOIN was unecessary. I have another question though. If I have a query like this...

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] table1.id, table2.id [color=green]FROM[/color] [color=orange]table1,[/color] table2 [!--sql2--][/div][!--sql3--]

...and I use mysql_fetch_assoc() to get the ids, how will I be able to tell them apart, I guess you could say.
Link to comment
Share on other sites

[!--quoteo(post=350792:date=Mar 1 2006, 09:52 PM:name=Masna)--][div class=\'quotetop\']QUOTE(Masna @ Mar 1 2006, 09:52 PM) [snapback]350792[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Nevermind, JOIN was unecessary. I have another question though. If I have a query like this...

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] table1.id, table2.id [color=green]FROM[/color] [color=orange]table1,[/color] table2 [!--sql2--][/div][!--sql3--]

...and I use mysql_fetch_assoc() to get the ids, how will I be able to tell them apart, I guess you could say.
[/quote]
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] table1.id [color=green]AS[/color] id1, table2.id [color=green]AS[/color] id2 [color=green]FROM[/color] [color=orange]table1,[/color] table2 [!--sql2--][/div][!--sql3--]
Then once you have passed the query through mysql_fetch_assoc() you'll have an array with the index's id1 and id2.
Link to comment
Share on other sites

You are still doing a join. If you have two tables in the FROM part, you are doing a join. The comma is just another way to write INNER JOIN. Be sure you know what you are joining on and that you set up the WHERE conditions appropriately.

To answer your other question, there will be no error when you have duplicate return names, and you can still access them by the numeric index if you use mysql_fetch_array(), but mysql_fetch_assoc() will not work properly. Setting an alias, like SemiApoc showed you, is the almost always best way to deal with it.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.