Delete rows

2,091 views
Skip to first unread message

Shahar

unread,
Nov 1, 2011, 9:51:56 AM11/1/11
to MapInfo-L
Hello,

How can I delete row/s from a query, for example each second row?
I wrote the following query:

select * from Q_ToProcess1 where rowid mod 2 = 0 into qDelete

Now I want to delete all of the selected rows within the mapbasic
window or a code.
Can you help me?

Thank you.

Thomas Bacon

unread,
Nov 1, 2011, 9:59:07 AM11/1/11
to mapi...@googlegroups.com
Just so you are aware, deleting rows from a query will also delete the
rows from the base table that the query is based upon.

If you still want to do this, you can use the following code:

select * from Q_ToProcess1 where rowid mod 2 = 0 into qDelete

Delete from qDelete

HTH,

Tom Bacon
Graduate GIS Engineer
Asset Management South
Tel: 01444 472380
www.mouchel.com

Hello,

Thank you.

--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en


The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. Mouchel Limited, Registered in England at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX Registered No : 1686040

Shahar

unread,
Nov 1, 2011, 10:17:42 AM11/1/11
to MapInfo-L
I tried that (through the MB window) and nothing happened.
Is it possible or only within a code?

Thanks
> archives, feature requests, to visit our Wiki, visit the Welcome page athttp://groups.google.com/group/mapinfo-l?hl=en
>
> The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. Mouchel Limited, Registered in England at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX  Registered No : 1686040-הסתר טקסט מצוטט-
>
> -הראה טקסט מצוטט-

ssim...@baltometro.org

unread,
Nov 1, 2011, 10:21:51 AM11/1/11
to mapi...@googlegroups.com
Sorry to keep harping on this, but don't count on the value of rowid to mean
anything in a SQL query.

Spencer

Thomas Bacon

unread,
Nov 1, 2011, 10:23:32 AM11/1/11
to mapi...@googlegroups.com
Just tested it from the MB window and it works fine here. Not sure what else to suggest...

Shahar

unread,
Nov 1, 2011, 10:33:24 AM11/1/11
to MapInfo-L
You are right, I probably did something wrong at the first time.
If I want to save the original table I use the commit statemant, but
if I want to pack it (MB window again)??

Thank you

On 1 נובמבר, 16:23, "Thomas Bacon" <Thomas.Ba...@mouchel.com> wrote:
> Just tested it from the MB window and it works fine here. Not sure what else to suggest...
>
> Tom Bacon
> Graduate GIS Engineer
> Asset Management South
> Tel: 01444 472380www.mouchel.com
>
>
>
> -----Original Message-----
> From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Shahar
> Sent: 01 November 2011 14:18
> To: MapInfo-L
> Subject: [MI-L] Re: Delete rows
>
> I tried that (through the MB window) and nothing happened.
> Is it possible or only within a code?
>
> Thanks
>
> > The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. Mouchel Limited, Registered in England at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX  Registered No : 1686040-äñúø è÷ñè îöåèè-
>
> > -äøàä è÷ñè îöåèè-
>
> --
> You received this message because you are subscribed to the
> Google Groups "MapInfo-L" group.To post a message to this group, send
> email to mapi...@googlegroups.com
> To unsubscribe from this group, go to:http://groups.google.com/group/mapinfo-l/subscribe?hl=en
> For more options, information and links to MapInfo resources (searching
> archives, feature requests, to visit our Wiki, visit the Welcome page athttp://groups.google.com/group/mapinfo-l?hl=en-הסתר טקסט מצוטט-
>
> -הראה טקסט מצוטט-

Thomas Bacon

unread,
Nov 1, 2011, 10:37:42 AM11/1/11
to mapi...@googlegroups.com
Pack Table YourTable Graphic - To only pack graphical objects

Pack Table YourTable Data - To only pack table data

Pack Table YourTable Graphic Data - To pack both graphical objects and table data.

HTH,

Tom Bacon
Graduate GIS Engineer
Asset Management South
Tel: 01444 472380
www.mouchel.com


Warren Vick

unread,
Nov 1, 2011, 10:38:58 AM11/1/11
to mapi...@googlegroups.com
Hello Shahar,

MapInfo doesn't have a full implementation of the WHERE clause using the DELETE statement. The only thing you can do with DELETE is delete a whole table (which could be a query) or and expression using the "built-in" rowid field. e.g. "... where rowid = 1"

The two-phase operation detailed in the message below should be sound.

select * from Q_ToProcess1 where rowid mod 2 = 0 into qDelete

This will select every other record. Then:

delete from qDelete

will delete those rows. If doing this in the MapBasic window, you can hit F2 to open a browser window to see the Q_ToProcess1 and qDelete tables, and watch the rows turn grey when they're deleted. Don't forget you need to commit Q_ToProcess1 (or whatever the base table is) to make the changes permanent.

Hope that helps.

Regards,
Waren Vick
Europa Technologies Ltd.
http://www.europa.uk.com

-----Original Message-----
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Shahar
Sent: 01 November 2011 14:18
To: MapInfo-L
Subject: [MI-L] Re: Delete rows

Shahar

unread,
Nov 1, 2011, 10:46:21 AM11/1/11
to MapInfo-L
Thank you all so much!!!

On 1 נובמבר, 16:38, Warren Vick <wv...@europa.uk.com> wrote:
> Hello Shahar,
>
> MapInfo doesn't have a full implementation of the WHERE clause using the DELETE statement. The only thing you can do with DELETE is delete a whole table (which could be a query) or and expression using the "built-in" rowid field. e.g. "... where rowid = 1"
>
> The two-phase operation detailed in the message below should be sound.
>
> select * from Q_ToProcess1 where rowid mod 2 = 0 into qDelete
>
> This will select every other record. Then:
>
> delete from qDelete
>
> will delete those rows. If doing this in the MapBasic window, you can hit F2 to open a browser window to see the Q_ToProcess1 and qDelete tables, and watch the rows turn grey when they're deleted. Don't forget you need to commit Q_ToProcess1 (or whatever the base table is) to make the changes permanent.
>
> Hope that helps.
>
> Regards,
> Waren Vick
> Europa Technologies Ltd.http://www.europa.uk.com
> archives, feature requests, to visit our Wiki, visit the Welcome page athttp://groups.google.com/group/mapinfo-l?hl=en-הסתר טקסט מצוטט-
>
> -הראה טקסט מצוטט-

Shahar

unread,
Nov 1, 2011, 10:51:43 AM11/1/11
to MapInfo-L
Thomas, one more question...

If I use a join query previous to the query I wrote and then I try to
use the "delete from qDelete" it doesn't work.
I get a message - "Cannot delete from a view"
Why?

On 1 נובמבר, 16:37, "Thomas Bacon" <Thomas.Ba...@mouchel.com> wrote:
> Pack Table YourTable Graphic    - To only pack graphical objects
>
> Pack Table YourTable Data       - To only pack table data
>
> Pack Table YourTable Graphic Data       - To pack both graphical objects and table data.
>
> HTH,
>
> Tom Bacon
> Graduate GIS Engineer
> Asset Management South

Thomas Bacon

unread,
Nov 1, 2011, 10:58:33 AM11/1/11
to mapi...@googlegroups.com

ssim...@baltometro.org

unread,
Nov 1, 2011, 11:40:32 AM11/1/11
to mapi...@googlegroups.com
If you are starting from a join query, values of RowID are much less likely to be meaningful and you are much more likely to get undesired results.

How does your process make the physical position of a row in a join query meaningful?

Spencer

Shahar

unread,
Nov 2, 2011, 1:43:31 AM11/2/11
to MapInfo-L
I have a main table with duplicated rows. In order to delete them I
used group and count to find which rows appear more than once, and
saved that query as a table.
I then open that table and use a join query with the main table in
order to find the duplicated rows over there.
the final stage is another query that takes every other row (using
mod) and delete half of the second query.

I hope it was clear enough.

Of course I can do it using the delete button but I want to do it in
an MBX...

Thanks
Reply all
Reply to author
Forward
0 new messages