Solved

Can you use an Inline Query in mysql?

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now