帮我看看这个sql语句

发布于 2024-12-05 08:04:25 字数 608 浏览 1 评论 0原文

我正在使用 mysql 和 vb6 来执行此查询。

 sql = "select user_id, fname, middle, lname from users where NOT EXISTS (SELECT user_id FROM accounts where accounts.user_id = users.user_id) "

我想做的是从表 users 中获取记录列表,其中 user_id 在表帐户中不存在。我在这方面取得了成功,但是,我的 vb 代码有问题。

我希望在文本框的更改事件上,如果用户键入 1,则将显示所有以 1 开头的记录。我尝试这样做但无济于事..我有语法错误 ..顺便说一下,nuser_id 是文本框的值..

sql = "select user_id, fname, middle, lname from users where NOT EXISTS (SELECT user_id FROM accounts where accounts.user_id = users.user_id) and user_id like'" & nuser_id & "%'"""

有什么想法吗?谢谢..

im using mysql and vb6 to execute this query..

 sql = "select user_id, fname, middle, lname from users where NOT EXISTS (SELECT user_id FROM accounts where accounts.user_id = users.user_id) "

what i'm trying to do is to get the list of records from table users where the user_id does not exist on table accounts. i was successful on this, however, im having a problem with my vb code..

i want that on the change event of my textbox, if the user type 1, all the records starting with 1 will be displayed..i tried doing this but to no avail..i got syntax error
..by the way, the nuser_id is the value of text box..

sql = "select user_id, fname, middle, lname from users where NOT EXISTS (SELECT user_id FROM accounts where accounts.user_id = users.user_id) and user_id like'" & nuser_id & "%'"""

any idea? thanks..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请远离我 2024-12-12 08:04:25

未经测试,但可能有效:

sql = "SELECT users.user_id, fname, middle, lname FROM users WHERE users.user_id NOT IN (SELECT accounts.user_id FROM accounts WHERE accounts.user_id = " & nuser_id & ") AND users.user_id = " & nuser_id & " LIMIT 1"

我强烈建议您将变量 nuser_id 转换为整数(或者如果您的 id 不是数字,则通过 sql 转义它)。

顺便说一句:您的原始代码在 LIKE 之后泄漏了空格。

Not tested but might work:

sql = "SELECT users.user_id, fname, middle, lname FROM users WHERE users.user_id NOT IN (SELECT accounts.user_id FROM accounts WHERE accounts.user_id = " & nuser_id & ") AND users.user_id = " & nuser_id & " LIMIT 1"

I strongly suggest, that you cast the variable nuser_id to integer (or sql escape it if your ids aren't numbers).

Btw: Your original code was leaking a whitespace after the LIKE.

秉烛思 2024-12-12 08:04:25

试试这个:

sql = "select user_id, fname, middle, lname from users where NOT EXISTS (SELECT user_id FROM accounts where accounts.user_id = users.user_id and accounts.user_id like'" & nuser_id & "%')"

Try this:

sql = "select user_id, fname, middle, lname from users where NOT EXISTS (SELECT user_id FROM accounts where accounts.user_id = users.user_id and accounts.user_id like'" & nuser_id & "%')"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文