Results 1 to 5 of 5

Thread: Select records from database

  1. #1
    watersniper's Avatar
    Joined
    Dec 2012
    Posts
    113
    Userbars
    1
    Thanks
    20
    Thanked
    13/12
    DL/UL
    16/1
    Mentioned
    8 times
    Time Online
    1d 23h 14m
    Avg. Time Online
    N/A

    Select records from database

    This isn't neopets related, but since you guys are all brilliant programmers, maybe you have some experience and can shed some light?

    I'm using enterprise javabeans and have a database which uses EJB-QL (which doesn't seem to recognize REGEXP, otherwise I could use .\\b).
    I need to select records containing keywords, eg. "pin". And don't want it to return things "lynchpin" or "pineapple".

    Any idea how to do this?

    Edit: A clarification on the question --
    Essentially my column consists of chunks of text, and I'm looking for the records whose chunk of text contain a keyword.
    Normally it would be this way:
    SELECT e.column FROM TABLE e WHERE e.column LIKE '%pin%'
    However, this will cause records containing text with the terms 'lynchpin' and 'pineapple' to be chosen as well.

    So I'm looking for something that will bound the keyword, such as in regex: ".\bpin\b."

    Otherwise I will have to select all the records then run the text through a Pattern/Matcher to see if it returns false, which is inefficient.
    Last edited by watersniper; 07-03-2013 at 11:30 PM.

  2. #2
    Saiyan Race
    j03's Avatar
    Joined
    Dec 2011
    Posts
    13,751
    Userbars
    176
    Thanks
    5,935
    Thanked
    33,182/6,624
    DL/UL
    23/36
    Mentioned
    3,871 times
    Time Online
    564d 8h 35m
    Avg. Time Online
    3h 13m
    No experience with the environment you are working with but this should still be of use:

    (you need an account to see links)

    Check the solution given to that question.

    @(you need an account to see links)
    (you need an account to see links)
    (you need an account to see links)(you need an account to see links)

    ------------------------
    [02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
    ------------------------


  3. #3
    watersniper's Avatar
    Joined
    Dec 2012
    Posts
    113
    Userbars
    1
    Thanks
    20
    Thanked
    13/12
    DL/UL
    16/1
    Mentioned
    8 times
    Time Online
    1d 23h 14m
    Avg. Time Online
    N/A
    Sorry @(you need an account to see links) I don't really get how the example you suggested relates.

    Perhaps I should clarify my question.

  4. #4
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    Never used that DB, but this could/should work?
    Code:
    SELECT e.column FROM TABLE e WHERE e.column LIKE ' pin' 
    UNION
    SELECT e.column FROM TABLE e WHERE e.column LIKE 'pin '
    Better yet, does it support in? ie:
    Code:
    SELECT e.column FROM TABLE e WHERE e.column IN (' pin', 'pin ', "pin\n", "\npin") //etc

  5. #5
    watersniper's Avatar
    Joined
    Dec 2012
    Posts
    113
    Userbars
    1
    Thanks
    20
    Thanked
    13/12
    DL/UL
    16/1
    Mentioned
    8 times
    Time Online
    1d 23h 14m
    Avg. Time Online
    N/A
    Thanks, Zachafer, but EJBQL doesn't support that either. Your first solution would ignore any text such as these: ' pin,' , ' pin!', '(pin ', ' pin)' etc which are all valid syntactically in my chunks of text. In frustration I moved my database to mysql so I could use REGEXP.

    In case anyone ever stumbles upon this thread with the same problem, one workaround is to enter all the allowed values in another table, then you could write
    SELECT DISTINCT e.column FROM FirstTable e, ValueTable v WHERE e.column LIKE v.value

    Sucks if your keyword constantly changes though.

Tags for this Thread

Posting Permissions

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