Help with SQL query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Help with SQL query

Post by ddragas »

Why doesn't this work?

Code: Select all

$result = mysql_query("select Sifra_apartmana from apartmani 
					where apartmani.iznajmljivac = '$broj' 
					and Sifra_apartmana NOT in
					(
						select smjestaj from banner
						where ((prikazivati_do <= '$danas') or
						(banner.prikazivati >= banner.prikazano))
					 )
					order by apartmani.vrsta_smjestaja ") or die (mysql_error());
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Moved from PHP Code to Databases...

What error do you get? Does your version of MySQL support subqueries?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

pickle wrote:Moved from PHP Code to Databases...

What error do you get? Does your version of MySQL support subqueries?
right now I've been reading topic that asked the same question

MySQL Servers and Clients 3.23.47
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

error is

Code: Select all

You have an error in your SQL syntax near 'select smjestaj from banner where ((prikazivati_do <= '1139349957') or ' at line 5
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Subqueries were added in 4.1 I believe.. so you can't use them.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

I've also found answer on some post.

Thank you both for reply
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Depending on the mysql version, it could be that subqueries were not supported...
Post Reply