1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

SQL Query Problem

Discussion in 'MySQL' started by JudyJiaStyle, May 2, 2007.

  1. #1
    What's wrong with this SQL statement?

    SELECT BookRec.AltAu, BookRec.Published, BookItem.Location, BookRec.Title, BookRec.Author, BookItem.CALLNBR, BookRec.Oclcno, BookItem.Avail FROM BookRec JOIN BookItem ON BookRec.OCLCNO = BookItem.OCLCNO WHERE Author or AltAu LIKE N'%smith%' ORDER BY title

    I'm writing a book catalog and sometimes each book has many authors, so other authors get cataloged into the AltAu field. But when people are searching by Author, I want them to also search the AltAu field.

    This statement works when I don't add the 'or AltAu', but I don't how how else to represent my query?

    Help!
     
    JudyJiaStyle, May 2, 2007 IP
  2. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #2
    SELECT BookRec.AltAu, BookRec.Published, BookItem.Location, BookRec.Title, BookRec.Author, BookItem.CALLNBR, BookRec.Oclcno, BookItem.Avail FROM BookRec JOIN BookItem ON BookRec.OCLCNO = BookItem.OCLCNO WHERE Author LIKE '%smith%' or AltAu LIKE '%smith%' ORDER BY title
     
    SoKickIt, May 2, 2007 IP
  3. LittlBUGer

    LittlBUGer Peon

    Messages:
    306
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yup, SoKickIt is correct, though in my opinion I tend to stay away from using LIKE in my SQL queries. That's just me though, I've just had bad experiences with them in the past. :)
     
    LittlBUGer, May 3, 2007 IP
  4. JudyJiaStyle

    JudyJiaStyle Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Not to sound all fangirly, but OMG THANK YOU! :)

    I'll experiment with the 'un-LIKE' options as well. I just used whatever was inherited from the old script :D
     
    JudyJiaStyle, May 3, 2007 IP
  5. LittlBUGer

    LittlBUGer Peon

    Messages:
    306
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm glad you got it working. I just meant that using the LIKE clause can yield unexpected results sometimes, compared to an exact criteria. :)
     
    LittlBUGer, May 3, 2007 IP
  6. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #6
    SoKickIt, May 3, 2007 IP