Gossamer Forum
Home : Products : Gossamer Links : Discussions :

SQL query to assign category

Quote Reply
SQL query to assign category
Having started out with a database of records that were originally imported to my Links table using MySQLMan, none of the original records had any category assignments. Links will only export records which have been assigned to categories.

What I need is a SQL query that will assign all links without a category to a category named Default and leave all others alone. Can anyone help with this?
Quote Reply
Re: [surfsafely] SQL query to assign category In reply to
That would be a bit complicated since the Category IDs are stored in the CatLinks intersecting table.

What you could try doing is the following:

1) Only import the LINKID into the CatLinks table.

--> if you are successful, then execute the following SQL Statement in the SQL Monitor option in MySQLMan:

Quote:

UPDATE CatLinks SET CategoryID = 'someid' WHERE CategoryID = ''


I am not sure if a '0' is inserted or if that column is left as an empty string, which if it does, then the above SQL statement would work.

Or you could copy the LinkIDs into another spreadsheet and then add another column called CategoryID and add in a default value in that column for all records...then IMPORT the spreadsheet into your CatLinks table in your LINKS database.
========================================
Buh Bye!

Cheers,
Me

Last edited by:

AnthroRules: Oct 14, 2001, 8:33 PM
Quote Reply
Re: [surfsafely] SQL query to assign category In reply to
It's going to be two steps:

1. Run:

SELECT ID FROM Links LEFT OUTER JOIN CatLinks WHERE Links.ID = CatLinks.LinkID AND CatLinks.LinkID IS NULL

That will generate a list of Link ID's that are not in a category. You need to take those and create the following query:

2. INSERT INTO CatLinks (LinkID, CategoryID) VALUES (a, 1), (b, 1), (c, 1) ...

Where a,b,c are the ID numbers pulled from step 1, and 1 is the category id you want to put things in.

Not the easiest I know.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] SQL query to assign category In reply to
Can't get past Step 1:

Error

MySQL said: parse error near 'WHERE Links.ID = CatLinks.LinkID AND CatLinks.LinkID IS NULL' at line 1.

Query: SELECT ID FROM Links LEFT OUTER JOIN CatLinks WHERE Links.ID = CatLinks.LinkID AND CatLinks.LinkID IS NULL