Jump to content


Photo

Inner Join


  • Please log in to reply
3 replies to this topic

#1 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 06 April 2006 - 02:36 PM

Hi guys,

When the user login, my auth-code save some information in a session, one of these information is the user flag.

I have 3 tables:
* user_data
* user_group
* user_flag

I verify the login/pass in [user_data], so, I start to record the session. I record:

* usr_name
* usr_id
* usr_group
* usr_flag

My problem is with the flag.. A flag just have a group_id with it. So, i was using a INNER JOIN to retrieve this flag_id, but not so happy, something was wrong.

My code:

    $str_sql = '
SELECT
    user_flag.id AS id
FROM
(
    user_flag
    INNER JOIN
    (
        user_group
        INNER JOIN
            user_data
        ON
            user_group.id = user_data.id_group
    )
    ON
        user_flag.id_group = user_group.id
)
WHERE
    user_data.id = '. $int_id .'
LIMIT
    1
    ';
So, if someone know what I do wrong, I will be greatful, I'm new in mysql.. ^^"!

Bye.
(If something is wrong, please tell me. I'm learning this language. Thank you)

#2 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 06 April 2006 - 03:11 PM

I've tried to built it on MS Access, and it give me this code, but still don't working..

        $str_sql        = '
SELECT
    user_flag.id
FROM
(
    user_group
    INNER JOIN
        user_flag
    ON
        user_group.id = user_flag.idgrupo
)
INNER JOIN
    user_data
ON
(
    user_flag.id = user_data.id
)
AND
(
    user_group.id = user_data.id_grupo
)
WHERE
    user_data.id = '. $int_id .'
LIMIT
    1
        ';

(If something is wrong, please tell me. I'm learning this language. Thank you)

#3 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 06 April 2006 - 03:52 PM

$sql = 'SELECT f.id FROM user_flag f
INNER JOIN user_data d ON d.id_group=f.id_group
WHERE d.id = '.$int_id;

Sounds a lot easier than what your code is doing. Am I missing something?

#4 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 06 April 2006 - 04:37 PM

Yeah, sounds a lot easier than mine..

=) Thank you! I'm testing but think is all here.

And its work well =D thanks
(If something is wrong, please tell me. I'm learning this language. Thank you)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users