Jump to content

If statement inside query based on other table's data


jimmyoneshot

Recommended Posts

Yep I know but the problem is I'm not sure of any other way around it query wise without doing 1 complete mysql_query to get the logged in user's id and user_type and then doing another complete mysql_query to get the extra user details based on the user_type and user_if retrieved from the first query.

 

Like you said I'm not sure it's possible to do what I'm after in 1 query  :shrug:

Hi

 

Just use the syntax in my first post on this thread.

 

SELECT *
FROM users
LEFT OUTER JOIN regular_user_details ON users.id = regular_user_details.userid
LEFT OUTER JOIN business_user_details ON users.id = business_user_details.userid 

 

All the best

 

Keith

Aha gotchya so it would only be the result that has empty/null fields not the database as obviously I would be doing this:-

 

SELECT users.id, users.user_type, regular_user_details.name, regular_user_details.surname, regular_user_details.address, regular_user_details.age, business_user_details.company, business_user_details.contact, business_user_details.fax

FROM users

LEFT OUTER JOIN regular_user_details ON users.id = regular_user_details.userid

LEFT OUTER JOIN business_user_details ON users.id = business_user_details.userid

 

WHERE users.username = 'blah' AND users.password = 'blah'

 

And then if I have any more user types I just join onto those tables too correct?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.