Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can you use an Inline Query in mysql?

Posted on 2004-03-24
4
Medium Priority
?
1,280 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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

618 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