SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile where conditions in select code

    I have a mysql data base with name and pass as the fields. Name is the primary key. Name and pass are defined as varchar(10) and varchar(30) respectively. How do you do multiple where conditions ? for example select * from auth
    where name = "ed" and where pass = "breedon" ; Is that correct code ?

  2. #2
    SitePoint Guru Marc's Avatar
    Join Date
    Nov 2000
    Location
    New York
    Posts
    765
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I think thats the SQL.. something like this should work:
    "SELECT * FROM tablename WHERE name="ed" AND pass="breedon";
    Marc Gugliuzza
    marc.gugliuzza.com



  3. #3
    SitePoint Guru dragonhawk's Avatar
    Join Date
    Apr 2002
    Location
    Melbourne
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you're supposed to use single quotes:

    SELECT * FROM tablename WHERE name='ed' AND pass='breedon'

    and just a word of advice, don't use the fieldname "name". You might find it a problem when using it since I think it's a reserved word.

    I remember the time when I used "From" as a fieldname and it caused a bunch of problems when I try to update that field via PHP

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes,
    Code:
    SELECT ID,Name FROM From WHERE Where="AND" AND Or="NOT";
    is confusing for humans (and illegal as an SQL statment)!!!

    However, reserved words can be used quite legally (an less confusingly) by simply encapsulating them with square brackets like so:
    Code:
    SELECT ID,Name FROM [From] WHERE [Where]="AND" AND [Or]="NOT";
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


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
  •