Jump to content

Recommended Posts

[code]select * from Content where section = (SELECT section from Sections where sectionName = 'Welcome')[/code]

Now [code]
SELECT section from Sections where sectionName = 'Welcome'
[/code]
Works fine and returns the value of 1.

This[code]
select * from Content where section = '1'
[/code]
Works fine and returns the record that I am looking for.

However, [code]
select * from Content where section = (SELECT section from Sections where sectionName = 'Welcome')[/code]
Gives an error - in the form of this:[quote]
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 section
FROM Sections
WHERE sectionName =  'Welcome'  )[/quote]

I have version 4.0.18 installed, using phpmyadmin 2.5.2 (my host controls these obviously) but surely nested queries work fine in these versions? I read up on them as well, but the syntax is exactly (as far as I can see) identical - so I am wondering if anyone can see anything wrong with their fresh eyes.
The two tables are called:
Content
Sections

Sections has section and sectionName as it's fields, section as a tinyint(4), and sectionName as a varchar(50). There is one entry, section = 1, sectionName = Welcome.

Content has a field called section which is also tinyint(4) - the two fields I am matching.
There is one entry (obviously more fields) but the section field is 1... to correspond to the welcome :P

Really struggling to see what maybe the problem, and hoping (as i said) some fresh or more experienced eyes may see a problem. Thanks for your time :)

(Oh yeah, am converting my previously working mssql to mysql queries as I swap databases... hence not that familiar with mysql tbh).
Link to comment
https://forums.phpfreaks.com/topic/14280-issue-with-a-nested-query-solved/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.