Solved

Can you use an Inline Query in mysql?

Posted on 2004-03-24
4
1,273 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

Upcoming Webinar: Securing your MySQL/MariaDB data

Join Percona’s Chief Evangelist, Colin Charles as he presents Securing your MySQL®/MariaDB® data on Tuesday, July 11, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 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