selecting 2 diffrent sqls tables in the database

Started on the old forum in October 2010 · view the original in the archive · old links redirect here

#select-2-sql-tables-in-1

1 reply · 425 views · started 16 years ago · 1 min read

2 participants
hyperlad Junior · 23 posts #1

Hi everyone hope your all good, I need help So i have a idea how to do it ,I have used search obviously before I posting this and looked on google but its not a detailed version of the idea I neeed , Right oh I want to select to two or more diffrent tables ok, for various codes Im using both Lavalair and wapdesire v2 but obviously in Lavalair birthday, top poster , shouter , member etc is in the users of the sqls part, but on the v2 of the script they are in profiles as you all no, Now I need to join them so I can select username from users and birthday etc from profiles I tried so many various ways its mad as its not having it, now the following code is actually from the v2 script

 
[SIZE=2]$birthday=mysql_fetch_array(mysql_query("SELECT b.birthday FROM users a INNER JOIN profiles b ON a.id=b.username WHERE a.id='".$username."'"));[/SIZE]

But I cant seem get this working it should work because it calls the db for other stuff , as i said I dont just want it for birthday Im converting alot of stuff to try work for v2 so its not just the birthday code its for everything Im asking for help, Thanks for reading hope your Ideas can gimme bit insipration how to do it Thankyou Tony 🙂

GumSlone Administrator Principal · 1,690 posts #2

hmmmm, not sure if this will work better in your case, but you can try.

$birthday=mysql_fetch_array(mysql_query("SELECT profiles.birthday FROM users LEFT JOIN profiles ON profiles.username=users.id WHERE users.id='".$username."'"));

but why you want to use join for this query if you select only one row, and profile and users have the same values "usernames" saved?

this query will be enough.

$birthday=mysql_fetch_array(mysql_query("SELECT profiles.birthday FROM profiles WHERE profiles.username='".$username."'"));

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close