?
Solved

Can you use an Inline Query in mysql?

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 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