• 0

SELECT LIKE search term


Question

hi guys i am having trouble with the syntax of a query here is what i have not shore where to go from here


select * from `jcow_accounts` WHERE 1 AND (username LIKE craig% OR email LIKE craig% OR fullname LIKE craig%) AND birthyear>1953 AND birthyear<1995 AND gender=0 and !hide_me order by lastlogin DESC LIMIT 20
[/CODE]

Thanks

Link to comment
https://www.neowin.net/forum/topic/1153440-select-like-search-term/
Share on other sites

4 answers to this question

Recommended Posts

  • 0

your like clauses are strings and need encapsulated in single quotes also.... LIKE '%craig' LIKE '%craig%' LIKE 'Craig%' etc

also what SQL variant? MS SQL, Oracle and MySQL all have differences even though they are close to the SQL standard

on SQL Server I'd write that like this

SELECT TOP 20 *

FROM [JCOW_ACCOUNTS]

WHERE ([uSERNAME] LIKE 'craig%' OR LIKE 'craig%' OR [FullName] LIKE 'craig%')

AND [birthyear] between 1953 AND 1995

AND [Gender] = 0

and HIDE_ME <> 1

ORDER BY [LastLogin] DESC

  • Like 1
  • 0

First,


1
[/CODE]

in the WHERE clause is not a propper boolean expression. What did you want to say with it?

[CODE]
1=1
[/CODE]

will give you ever row.

[CODE]
1<>1
[/CODE]

will give you none.

Also, you have to enclose your strings in single quotes:

[CODE]
username LIKE 'craig%' OR email LIKE 'craig%' OR fullname LIKE 'craig%'
[/CODE]

  • Like 1
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Too soon, I'm still not over this death!
    • Normally, I admit when a title is clickbait (unfortunately, it's become somewhat necessary in AI-dominated news sections today), but in this case, all supported versions is implied and doesn't need to be spelled out in the title. Of course, I'm covering a Patch Tuesday update but that is only available to supported Windows SKUs. All our coverage relates to supported Windows software and SKUs only unless we expressly state that it's "unsupported", "unofficial", or "third-party". I'm sorry, but supported/official SKUs don't need to be spelled out as such in every Neowin headline.
    • ALL versions or ALL SUPPORTED versions? Neowin does it again.
    • But the reality is it will work for people's needs, and they don't care about the technology that makes it. Clearly not everyone's needs, but that low end space where personal laptops were only used to type emails, watch content and browse websites, but they didn't want to do that on a small screen device. Heck, writing that out I can now see the connection and reason it'll do so well. Apple is about experience. If the experience is bad, they don't release it. Low end Windows laptop manufacturers up until this point have not taken that into consideration ever before, so slow laggy usage with brittle slimey plastic shells were common. I hope that the low end space at least creates better physical products that last a bit longer, and if Microsoft get their act together, they could also have a solid OS on such low end hardware that would actually make the experience work for what the hardware was intended for. The fact that the CPU is a "cellphone", sorry mobile phone processor is irrelevant. It's about the experience, and so far, that sounds quite solid.
  • Recent Achievements

    • Week One Done
      Jordan Smith earned a badge
      Week One Done
    • Reacting Well
      BizSAR earned a badge
      Reacting Well
    • First Post
      AndreaB earned a badge
      First Post
    • Week One Done
      Huge Trailer earned a badge
      Week One Done
    • Week One Done
      Classifyskilleducation earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      595
    2. 2
      +Edouard
      186
    3. 3
      PsYcHoKiLLa
      77
    4. 4
      Michael Scrip
      73
    5. 5
      Steven P.
      65
  • Tell a friend

    Love Neowin? Tell a friend!