Solved

Can you use an Inline Query in mysql?

Posted on 2004-03-24
4
1,268 Views
Last Modified: 2007-12-19
Can you use an Inline Query in mysql?

I am not sure if it is even possible and I can't find any documentation on it or make it work...

Hope you can help!!

SELECT c.NAME catname,
            t.ID id,
            t.title,
            u.USERNAME username,
            DATE_FORMAT(t.date,'%d/%m/%Y %h:%i%p') date,
            p.p_date
FROM category c,
         topics t,
         users u,
         (SELECT max(date) p_date
                    , topic_id p_topic_id
          FROM post
          GROUP BY topic_id) p
WHERE t.cat_id = c.ID
AND t.USERID = u.ID
AND p.p_topic_id = t.id
ORDER BY t.date DESC


Is there an equivalent if you cannot do it this way?


Dave
0
Comment
Question by:dazzled1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Expert Comment

by:william_jwd
ID: 10669094
I think, this should work...
What is the error you are getting...
0
 
LVL 1

Author Comment

by:dazzled1
ID: 10669575
I get the following error.


MySQL said:


#1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT max( date ) p_date, topic_id p_topic_id
FROM post
GROUP



This would work in Oracle... Unfortuantely I am not an expert in MYSQL
0
 
LVL 1

Author Comment

by:dazzled1
ID: 10670102
Right up to 500 points now!
0
 
LVL 14

Accepted Solution

by:
psadac earned 500 total points
ID: 10671239
if you have mysql version > 5.0 perhaps your query works. for all other versions :

SELECT c.NAME AS catname,
            t.ID AS id,
            t.title,
            u.USERNAME AS username,
            DATE_FORMAT(t.date,'%d/%m/%Y %h:%i%p') AS date,
            MAX(p.date) AS p_date
FROM category AS c INNER JOIN topics AS t ON c.ID = t.cat_id
                              INNER JOIN users AS u ON t.USERID = u.ID
                              INNER JOIN post AS p ON p.topic_id = t.id
GROUP BY t.topic_id
ORDER BY t.date DESC
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question