Select rows from column with same value

Go To StackoverFlow.com

0

I have a table of book authors, and am trying to get a query result of books by a certain author.

Something like

SELECT * FROM mytable WHERE authors = Carl Sagan

I need all of the columns for each row that matches.

Any help would be appreciated, I'm new to SQL.

Thanks!

2012-04-04 00:03
by user974703
From your description, your query should work. Are you getting errors - Mike Parkhill 2012-04-04 00:07
Show us the table definitio - Shiplu Mokaddim 2012-04-04 00:42
as you are new to sql, I think your tables will be incorrectly created. Is relationship created correctly - levi 2012-04-10 13:21


3

Just to clarify, Assumptions: 1.) Carl Sagan authored more than one item in this table. 2.) You want to return all of the occurrences of Carl Sagan.

Original: SELECT * FROM mytable WHERE authors = Carl Sagan

Should Be: SELECT * FROM mytable WHERE authors = 'Carl Sagan'

FYI, I use HeidiSQL to test queries. Let me know if that helps.

2012-04-04 00:16
by Ryan Kazinec
HeidiSQL is a MySQL tool, the question is tagged with PostgreSQLa_horse_with_no_name 2012-04-04 16:52
Thank you for pointing that out. I'm new to this website and did not notice the tag - Ryan Kazinec 2012-04-04 20:05


2

You have the query correct except that you need to have the text you're comparing to delimited as a string:

SELECT * FROM mytable WHERE authors='Carl Sagan'
2012-04-04 00:06
by QuantumMechanic
d'oh! that was it - user974703 2012-04-04 00:14
If your answer is solved please remember to select a reply as the answer - TryHarder 2012-04-04 01:06


1

Your question seems unclear to me, but modify your query by putting a single quote

SELECT * FROM mytable WHERE authors = 'Carl Sagan'
2012-04-04 00:07
by John Woo