Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7803647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:39:09+00:00 2026-06-02T01:39:09+00:00

I have the following query, and would like to list only the first match.

  • 0

I have the following query, and would like to list only the first match.

$first = $_GET['category'];
$first = $first[0] . "%";

$query = mysql_query("SELECT * FROM lyrics WHERE authorclean LIKE '".$first."'") or die(mysql_error());

(?category=b)

So DISTINCT could do this right? This is what I tried, but did not work:

$query = mysql_query("SELECT DISTINCT authorclean FROM lyrics WHERE authorclean LIKE '".$first."'") or die(mysql_error());

EDIT: Here is the full code:

function getCategory() {
$first = $_GET['category'];
$first = $first[0] . "%";

$query = mysql_query("SELECT DISTINCT authorclean FROM lyrics WHERE authorclean LIKE 'B%'") or die(mysql_error());
//$query = mysql_query("SELECT * FROM lyrics WHERE authorclean LIKE '".$first."'") or die(mysql_error());
if(mysql_num_rows($query) == 0) {
    echo "Geen resultaten gevonden.";
} else { 
while ($row = mysql_fetch_assoc($query)) { ?>
    <p><a href="/<?= $_GET['category']; ?>/<?= strtolower($row['authorclean']); ?>/"><?= $row['author']; ?></a></p>
    <?php }
    }
}

(B% is just for testing)

If I run this following query in the database directly I get two results. If I run with the code above I just get an empty page (except for the html thats already there).

SELECT DISTINCT authorclean FROM lyrics WHERE authorclean LIKE 'B%'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:39:10+00:00Added an answer on June 2, 2026 at 1:39 am

    If you have a a table “tbl_lyrics” with fields: author lyrics year and is filled for example as follows:

    author_A       lyrics_A        year_A
    author_A       lyrics_A1       year_A1
    author_A1       lyrics_A2       year_A
    author_B        lyrics_B1       year_B1
    

    if you do

    select distinct(author) from tbl_lyrics where author like '%author_A%'
    

    you are going to get: author_A and author_A1. NOT the first one that matches.

    If you want the first one that matches you can do:

    select author from (select distinct(author) as author from tbl_lyrics where author like '%author_A%') where rownum <2;
    

    this will return author_A only.

    Limit is used with MySql but would not work with oracle databases

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: mysql_query(SELECT * FROM list WHERE name LIKE '%'$searchTerm'%' OR
I have following query , select * from process where name like 'abc'; now
I have the following query that works well. SELECT DISTINCT city,region1,region2 from static_geo_world where
I have following query: $query=SELECT language_value, votes, user_id FROM labels WHERE approved=1 AND label_value=.
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER
I have the following query: SELECT item.`ID`, item.`Name`, item.`UnitCost`, item.`Price`, discount.`rate` FROM item INNER
I have the following query to select users and their locations, etc from MySQL
I have a Recordset obtained by the following query: SELECT DISTINCT [Number] FROM NUMBERS
I have the following rss feed which I would like to query to get
I have the following query to count all data every minute. $sql= SELECT COUNT(*)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.