0

I've got a table, called for example, "node", from which I need to return values for as shown:

SELECT nid FROM node WHERE type = "book"

After I get a list of values let's say:

|**nid**|
|123|
|12451|
|562|
|536|

Then I need to take these values, and check another table, for rows where column 'path' has values as "node/123", "node/12451" (numbers the previous request returned) in one joined request. It all would be easier if collumn 'path' had simple numbers, without the 'node/'. And then also count the number of identical i.e. 'node/123' returned. End result would look like:

nid |  path  | count(path) | count(distinct path) 
123 |node/123|  412        |       123        
562 |node/562|  123        |       56   

Works fine if done in multiple separated queries, but that won't do.

1
  • How can count(distinct path) be different from 1 for a given nid/path pair? Commented Dec 3, 2009 at 14:26

3 Answers 3

1
select a.nid from node a join othertable b 
on b.path = concat("node/", a.nid) where type='book'
Sign up to request clarification or add additional context in comments.

Comments

0

You can probably do something like the following (nid may require additional conversion to some string type):

SELECT *
FROM OtherTable
JOIN node ON path = CONCAT('node/', nid)
WHERE type = 'book'

Comments

0

Thank you all for your help. Basically, the problem was that I didn't know how to get nid and node/ together, but concat helped. End result looks something like:

  SELECT node.nid, accesslog.path, count(accesslog.hostname), count(distinct accesslog.hostname)
    FROM `node`, `accesslog`
   WHERE node.uid=1
     AND node.type='raamat' 
     AND accesslog.path = CONCAT('node/', node.nid)
GROUP BY node.nid

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.