SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    trip ket's Avatar
    Join Date
    Feb 2004
    Location
    Portugal
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with easy mysql query - show name of clients with "gold" card

    Hello fellas,

    Need a bit of help with an easy mysql query.

    I have a database with two tables:

    - one table named "clients" which has 5 columns (id_client, name, address, date, and phone)
    - the other table named "cards" which has 5 columns as well (id_card, bank, type, category, id_client)

    The "type" column on the "cards" table is ENUM and can either be "gold" or "normal". (it's related to the type of bank card.. visa, gold, etc..)

    I need a query that shows the name of the clients that have the "gold" card.

    Any ideas? Thanks!
    oi!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,248
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    what have you tried?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    trip ket's Avatar
    Join Date
    Feb 2004
    Location
    Portugal
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi r937,

    i'm trying as we speak. i'm suppose to use inner join, right?

    thanks.
    oi!

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,248
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    yes
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    trip ket's Avatar
    Join Date
    Feb 2004
    Location
    Portugal
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i've tried the following code with no success, still reading more about it..

    SELECT cards.type, clients.name
    FROM cards
    INNER JOIN clients ON cards.type= clients.id_cliente
    WHERE cards.type= 'gold'
    do i need to SELECT the clients.id_client as well?
    oi!

  6. #6
    trip ket's Avatar
    Join Date
    Feb 2004
    Location
    Portugal
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    after reading and checking this example, i was able to create the following query:


    SELECT clients.name, cards.type, cards.id_client
    FROM clients
    INNER JOIN cards
    ON clients.id_client = cards.id_client
    WHERE cards.type = 'gold'
    correct? right?
    oi!

  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,248
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by ket View Post
    correct? right?
    what happened when you tested it?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  8. #8
    trip ket's Avatar
    Join Date
    Feb 2004
    Location
    Portugal
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, it displayed the names of the clients that have the Gold card, just like i wanted
    oi!

  9. #9
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,248
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    glad i could help

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  10. #10
    trip ket's Avatar
    Join Date
    Feb 2004
    Location
    Portugal
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    eheheh rudy, thanks for the help
    oi!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •