SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    ireland
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ambiguous! I don't understand

    Can some one help me with the following

    I keep getting this error

    #1052 - Column: 'county_id' in where clause is ambiguous

    with the following SQL command

    SELECT contact_name,contact_number,secondary_level,junior_subjects
    FROM users,secondary_level,grind_record,counties,junior_subjects
    WHERE users.user_id = grind_record.user_id
    AND secondary_level.secondary_level_id = grind_record.secondary_level_id
    AND junior_subjects.junior_subject_id = grind_record.junior_subject_id
    AND county_id = "23"

    If I replace county_id with county_name and put in a value then it works but I want to be able to pass my county_id to this command

    Tks

  2. #2
    I want my 4th arrow! garlinto's Avatar
    Join Date
    Jun 2002
    Location
    Riding the electron wave
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that join syntax is much easier to troubleshoot and maintain. Try this query and see if it works for you. Paste it into phpMyAdmin ( if you are running MySQL) and see what happens. Post again with any error messages if you are still having trouble.

    I wasn't too sure about what you wanted from table.grind_record, so I just made the query select everything from that particular table.

    Code:
    SELECT us.contact_name, us.contact_number, sec.secondary_level, js.junior_subjects, gr.*
        FROM users us
        LEFT JOIN grind_record gr 
          ON us.user_id = gr.user_id
        LEFT JOIN  secondary_level sec
          ON sec.secondary_level_id = gr.secondary_level_id
        LEFT JOIN junior_subjects js
          ON js.junior_subject_id = gr.junior_subject_id
        WHERE counties.county_id = "23"
    Ducharme's Axiom: "If you view your problem closely
    enough, you will recognize yourself as part of the problem."


  3. #3
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    What that means is that country_id is in more than one table and you need to specify which table to use (like garlinto explained).

  4. #4
    I want my 4th arrow! garlinto's Avatar
    Join Date
    Jun 2002
    Location
    Riding the electron wave
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hartmann
    What that means is that country_id is in more than one table and you need to specify which table to use (like garlinto explained).
    Thanks for making that point clear hartmann. I forgot to explicitly mention where the error was comming from, even though the revised query explained it.
    Ducharme's Axiom: "If you view your problem closely
    enough, you will recognize yourself as part of the problem."



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
  •