Re: [sqlite] Finding a single row
On 26 May 2016, at 12:17pm, Ertan Küçükoğluwrote: > Two or more rows return is an error on user definition. I will popup a > message in this case. Actually you can test for that just before you're about to insert a new row into the table. So rather than return an error when someone is searching for a code you can return an error instead of corrupting your FIYATKODLARI table. Simon. ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Finding a single row
On 2016/05/26 1:17 PM, Ertan Küçükoğlu wrote: Hi Simon, Two or more rows return is an error on user definition. I will popup a message in this case. Thanks for the example, I didn't know <= can be used also for strings. I think Simon's example said LIMIT 1 at the end, did you use that? The ORDER BY and LIMIT is very important to the success of that query. If used correctly, it is impossible to get more than 1 row. Regards, Ertan Küçükoğlu -Original Message- From: sqlite-users-boun...@mailinglists.sqlite.org [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On Behalf Of Simon Slavin Sent: Thursday, May 26, 2016 1:55 PM To: SQLite mailing list <sqlite-users@mailinglists.sqlite.org> Subject: Re: [sqlite] Finding a single row On 26 May 2016, at 11:44am, Ertan Küçükoğlu <ertan.kucuko...@1nar.com.tr> wrote: I need to find a single row in my table which begins as the complete card number, or I need to know no match exists in my table. What happens if two rows match ? Ignoring that question for a while, what you're looking for is the row which sorts immediately before the complete card code you're searching for. SELECT Kodu FROM FIYATKODLARI WHERE Kodu <= '' ORDER BY Kodu DESC LIMIT 1 In your programming langauge take a look at the value returned and see if it is the same as the first n characters of the value you're searching for. If it is, you have a match. If not, you don't. Simon. ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Finding a single row
Hi Simon, Two or more rows return is an error on user definition. I will popup a message in this case. Thanks for the example, I didn't know <= can be used also for strings. Regards, Ertan Küçükoğlu -Original Message- From: sqlite-users-boun...@mailinglists.sqlite.org [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On Behalf Of Simon Slavin Sent: Thursday, May 26, 2016 1:55 PM To: SQLite mailing list <sqlite-users@mailinglists.sqlite.org> Subject: Re: [sqlite] Finding a single row On 26 May 2016, at 11:44am, Ertan Küçükoğlu <ertan.kucuko...@1nar.com.tr> wrote: > I need to find a single row in my table which begins as the complete > card number, or I need to know no match exists in my table. What happens if two rows match ? Ignoring that question for a while, what you're looking for is the row which sorts immediately before the complete card code you're searching for. SELECT Kodu FROM FIYATKODLARI WHERE Kodu <= '' ORDER BY Kodu DESC LIMIT 1 In your programming langauge take a look at the value returned and see if it is the same as the first n characters of the value you're searching for. If it is, you have a match. If not, you don't. Simon. ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Finding a single row
On 26 May 2016, at 11:44am, Ertan Küçükoğluwrote: > I need to find a single row in my table which begins as > the complete card number, or I need to know no match exists in my table. What happens if two rows match ? Ignoring that question for a while, what you're looking for is the row which sorts immediately before the complete card code you're searching for. SELECT Kodu FROM FIYATKODLARI WHERE Kodu <= '' ORDER BY Kodu DESC LIMIT 1 In your programming langauge take a look at the value returned and see if it is the same as the first n characters of the value you're searching for. If it is, you have a match. If not, you don't. Simon. ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users